wx.lib.scrolledpanel 似乎默认支持鼠标滚轮垂直滚动,但不支持按下 shift 时的水平滚动。我找不到任何方法来激活它。它甚至在某个地方还是我应该自己编写一个合适的事件处理程序?如果是这样,该怎么做?
问问题
326 次
2 回答
0
要水平滚动,您必须将鼠标放在水平滚动条上,然后转动鼠标滚轮。
import wx
import wx.lib.scrolledpanel as scrolled
class TestPanel(scrolled.ScrolledPanel):
def __init__(self, parent):
scrolled.ScrolledPanel.__init__(self, parent, -1)
vbox = wx.BoxSizer(wx.VERTICAL)
desc1 = wx.StaticText(self, -1, "1. These lines are really quite long and should not fit in the window requiring you to use the horizontal scroll bar or position the mouse over the scroll bar and spin the wheel\n\n")
desc2 = wx.StaticText(self, -1, "2. These lines are really quite long and should not fit in the window requiring you to use the horizontal scroll bar or position the mouse over the scroll bar and spin the wheel\n\n")
desc3 = wx.StaticText(self, -1, "3. These lines are really quite long and should not fit in the window requiring you to use the horizontal scroll bar or position the mouse over the scroll bar and spin the wheel\n\n")
desc4 = wx.StaticText(self, -1, "4. These lines are really quite long and should not fit in the window requiring you to use the horizontal scroll bar or position the mouse over the scroll bar and spin the wheel\n\n")
desc5 = wx.StaticText(self, -1, "5. These lines are really quite long and should not fit in the window requiring you to use the horizontal scroll bar or position the mouse over the scroll bar and spin the wheel\n\n")
desc6 = wx.StaticText(self, -1, "6. These lines are really quite long and should not fit in the window requiring you to use the horizontal scroll bar or position the mouse over the scroll bar and spin the wheel\n\n")
vbox.Add(desc1, wx.NewId(), wx.ALIGN_LEFT|wx.ALL, 5)
vbox.Add(desc2, wx.NewId(), wx.ALIGN_LEFT|wx.ALL, 5)
vbox.Add(desc3, wx.NewId(), wx.ALIGN_LEFT|wx.ALL, 5)
vbox.Add(desc4, wx.NewId(), wx.ALIGN_LEFT|wx.ALL, 5)
vbox.Add(desc5, wx.NewId(), wx.ALIGN_LEFT|wx.ALL, 5)
vbox.Add(desc6, wx.NewId(), wx.ALIGN_LEFT|wx.ALL, 5)
self.SetSizer(vbox)
self.SetAutoLayout(1)
self.SetupScrolling(scroll_x=True, scroll_y=True, rate_x=20, rate_y=20, scrollToTop=True, scrollIntoView=True)
app = wx.App(0)
frame = wx.Frame(None, wx.ID_ANY,size=(500,200))
tp = TestPanel(frame)
frame.Show()
app.MainLoop()
于 2015-12-09T09:25:52.013 回答
0
您似乎可以使用 wx.EVT_SCROLLWIN 事件,并确保它调用一个简单的方法,将事件的方向设置为 wx.HORIZONTAL(当您按下 shift 时。)
sw = wx.ScrolledWindow(p, style = wx.HSCROLL)
def onScroll(event):
event.SetOrientation(wx.HORIZONTAL)
event.Skip()
sw.Bind(wx.EVT_SCROLLWIN, onScroll)
当您使用鼠标滚轮“在其中”滚动时,这将使滚动窗口沿水平方向滚动。这是您可以在控制台中粘贴的快速代码。
app = wx.App()
f = wx.Frame(None)
p = wx.Panel(f)
sw = wx.ScrolledWindow(p)
sw.SetScrollbars(20,20,500,500)
bb = wx.Button(sw, label='big button', pos=(0,0), size=(500,500))
def onScroll(event):
event.SetOrientation(wx.HORIZONTAL)
event.Skip()
sw.Bind(wx.EVT_SCROLLWIN, onScroll)
sz = wx.BoxSizer(wx.HORIZONTAL)
sz.Add(sw, 1, wx.EXPAND)
p.SetSizer(sz)
sz.Fit(f)
f.Show(); app.MainLoop()
于 2020-08-03T12:46:37.790 回答