wxPython水平滚动与shift +鼠标滚轮

时间:2015-12-07 23:06:26

标签: wxpython mousewheel wxwidgets scrolledwindow

默认情况下,wx.lib.scrolledpanel似乎支持鼠标滚轮垂直滚动,但在按下shift时不支持水平滚动。我找不到任何激活它的方法。它甚至在某个地方还是我应该自己编写适当的事件处理程序?怎么做,如果是的话?

2 个答案:

答案 0 :(得分: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()

答案 1 :(得分: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()