Python:确定哪个滚动条在ScrolledPanel中移动 [英] Python: Decide which scrollbar is moving in ScrolledPanel
问题描述
此问题继续以下链接上的问题:用于ScrolledPanel的wxPython事件.我对代码进行了一点编辑,以便OnScroll函数获得内容滚动条的x位置,并使用它来设置标题滚动条的x位置.
This question continue the question on the link : wxPython Event for ScrolledPanel. I edited the code a little bit so that OnScroll function get the x position of the content's scrollbar and use that to set x position of the header's scrollbar.
我的问题是我无法确定水平滚动条何时滚动.因此,无论何时滚动内容的任何滚动条,我的程序现在都会滚动标题的水平滚动条,而当内容的h-scrollbar滚动时,我希望标题的h-scrollbar也滚动. (或者,如果有人可以建议仅在滚动水平栏时触发事件触发,那将是非常好的).谢谢你.
My problem is I cannot decide when the horizontal scrollbar is rolled. So my program now has the header's horizontal scrollbar rolled whenever any of the content's scrollbars is rolled while I want the header's h-scrollbar rolled when the content's h-scrollbar is rolled. (Or if anyone can suggest an event triggering by only when scrolling the horizontal bar it will be very good). Thanks ahead.
import wx
from wx.lib.scrolledpanel import ScrolledPanel
header = """
col1 col2 col3 col4 col5"""
text = """
1336 733 1336 4732 1217
5968 4477 1217 5748 4477
1217 5635 4372 1217 5634
4369 1217 5633 4371 217"""
class Test(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, size=(300, 200))
self.panel=panel = wx.Panel(self, -1)
vbox = wx.BoxSizer(wx.VERTICAL)
vboxA = wx.BoxSizer(wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
self.headerPanel = headerPanel = ScrolledPanel(panel, -1, size=(150,32))
hboxHeader = wx.BoxSizer(wx.HORIZONTAL)
self.headertc = headertc = wx.TextCtrl(headerPanel, -1, header,
size=(500,32),style= wx.TE_READONLY)
headertc.Unbind(wx.EVT_SCROLLWIN)
hboxHeader.Add(headertc,1)
headerPanel.SetSizer(hboxHeader)
headerPanel.SetAutoLayout(1)
headerPanel.SetupScrolling(scroll_y = False)
hbox.Add(headerPanel,1, wx.EXPAND | wx.ALL,0)
vboxA.Add(hbox, 0, wx.EXPAND)
self.textPanel = textPanel = ScrolledPanel(panel, -1, size = (150,150))
textPanel.Bind(wx.EVT_SCROLLWIN, self.OnScroll)
hboxText = wx.BoxSizer(wx.HORIZONTAL)
self.tc = tc = wx.TextCtrl(textPanel, -1, text, size=(500,500),
style=wx.TE_MULTILINE|wx.TE_DONTWRAP| wx.TE_READONLY)
hboxText.Add(tc, 1)
textPanel.SetSizer(hboxText)
textPanel.SetAutoLayout(1)
textPanel.SetupScrolling(scroll_x=True, scroll_y=True)
vboxA.Add(textPanel,1, wx.EXPAND | wx.ALL,0)
vbox.Add(vboxA, 1, wx.EXPAND | wx.ALL)
panel.SetSizer(vbox)
self.Centre()
self.Show(True)
def OnScroll(self, event):
event.Skip()
x= event.GetPosition()
self.headerPanel.Scroll(x,0)
print event.GetEventType()
if __name__ == "__main__":
app = wx.App()
frame = wx.Frame(None, -1)
win = Test(frame, "Test scroll bar")
app.MainLoop()
推荐答案
使用以下条件检查滚动处理程序中的水平滚动.
Use the following condition to check for horizontal scrolling in your scroll handler.
if event.Orientation == wx.SB_HORIZONTAL:
这篇关于Python:确定哪个滚动条在ScrolledPanel中移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!