python滚动条位置_Python:确定哪个滚动条在ScrolledPanel中移动

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.

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:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值