wxPython使用shift和x2B进行水平滚动;鼠标滚轮

wxPython使用shift和x2B进行水平滚动;鼠标滚轮,wxpython,mousewheel,wxwidgets,scrolledwindow,Wxpython,Mousewheel,Wxwidgets,Scrolledwindow,默认情况下,wx.lib.Scrolled面板似乎支持鼠标滚轮垂直滚动,但在按下shift键时不支持水平滚动。我找不到任何方法来激活它。它甚至在某个地方,或者我应该自己编写一个合适的事件处理程序吗?如果是这样,如何操作?要水平滚动,必须将鼠标放在水平滚动条上,然后旋转鼠标滚轮 import wx import wx.lib.scrolledpanel as scrolled class TestPanel(scrolled.ScrolledPanel): def __init__(s

默认情况下,wx.lib.Scrolled面板似乎支持鼠标滚轮垂直滚动,但在按下shift键时不支持水平滚动。我找不到任何方法来激活它。它甚至在某个地方,或者我应该自己编写一个合适的事件处理程序吗?如果是这样,如何操作?

要水平滚动,必须将鼠标放在水平滚动条上,然后旋转鼠标滚轮

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()

似乎可以使用wx.EVT_SCROLLWIN事件,并确保它调用一个简单的方法,将事件的方向设置为wx.HORIZONTAL(当您按下shift键时)

这将使滚动窗口在水平方向滚动时,你滚动“在它”与鼠标滚轮。下面是一个可以粘贴到控制台中的快速代码

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()
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()