使滚动面板的水平滚动条在 wxPython 中永久可见 [英] Making the horizontal scrollbar of a scrolled panel to be permanently visible in wxPython
问题描述
我正在 Windows 8 操作系统上使用 wxPython v3.0 开发 GUI.我对特定滚动面板上的水平滚动条有疑问.在我的 GUI 中,有 2 个名为 panel1
和 panel2
的滚动面板添加到一个名为 mainPanel
的主滚动面板,并且该面板具有垂直滚动酒吧.当 mainPanel
的垂直滚动条移动时,所有面板(panel1 和 panel2)同时移动,这正是我想要的.同样在 panel1
中只有一个水平滚动条(使用 SetupScrolling(scroll_y=False)
在 panel1
上禁用垂直滚动条).我在 panel1
上需要水平滚动条的原因是,如果里面的文本增加,面板也会展开,所以我给了它一个滚动条.
I am developing a GUI with wxPython v3.0 on windows 8 OS. I have a problem regarding the horizontal scroll bar on a particular scrolled panel. In my GUI there are 2 scrolled panels named as panel1
and panel2
added to one main scrolled panel named as mainPanel
and this panel has a vertical scroll bar. When ever the vertical scroll bar of the mainPanel
is moved all the panels (panel1 & panel2) move simultaneously, this is exactly what I desired. Also in panel1
there is a horizontal scroll bar only (The vertical scroll bar is disabled on panel1
using SetupScrolling(scroll_y=False)
). The reason why I need a horizontal scroll bar on panel1
is because if the text inside increases the panel expands too so I gave it a scroll bar.
问题:
panel1
上的这个水平条只有在我滚动 mainPanel
的垂直滚动条(如图所示的最右侧的滚动条)时才可见至底部.
This horizontal bar on panel1
is only visible when I scroll the vertical scroll bar (the scroll bar on extreme right side as shown in the image.) of the mainPanel
to the bottom.
如何让 panel1
上的水平滚动条每次都可见?我不想先把mainPanel的垂直滚动条滚动到底部才能访问panel1的水平滚动条?
How can I make the horizontal scroll bar on panel1
to be visible every time? I don't want to first scroll the vertical scroll bar of the mainPanel to the bottom in order to access the horizontal scroll bar of panel1?
代码:这是此问题的示例代码.如果您有任何识别问题,也可以从此链接下载 python 文件.
Code: Here is an example code for this problem. You can also download the python file from this link if you have any problems with identations.
#!/usr/bin/env python
import wx
import wx.lib.scrolledpanel
class GUI(wx.Frame):
def __init__(self, parent, id, title):
screenWidth = 800
screenHeight = 450
screenSize = (screenWidth, screenHeight)
wx.Frame.__init__(self, None, id, title, size=screenSize)
locationFont = wx.Font(15, wx.MODERN, wx.NORMAL, wx.BOLD)
mainSizer = wx.BoxSizer(wx.VERTICAL)
panelsSizer = wx.BoxSizer(wx.HORIZONTAL)
sizer1 = wx.BoxSizer(wx.VERTICAL)
sizer2 = wx.BoxSizer(wx.VERTICAL)
mainPanel = wx.lib.scrolledpanel.ScrolledPanel(self, -1,style=wx.SIMPLE_BORDER)
mainPanel.SetupScrolling()
panel1 = wx.lib.scrolledpanel.ScrolledPanel(mainPanel, -1, style=wx.SIMPLE_BORDER)
panel1.SetupScrolling(scroll_y=False)
panel2 = wx.lib.scrolledpanel.ScrolledPanel(mainPanel, -1, style=wx.SIMPLE_BORDER)
panel1.SetBackgroundColour('#FFFFFF')
panel2.SetBackgroundColour('#FFFFFF')
panelsSizer.Add(panel1, 1, wx.EXPAND)
panelsSizer.Add(panel2, 2, wx.EXPAND)
mainPanel.SetSizer(panelsSizer)
k = 0
locations = [1,2,3,4,5,6,7,8,9,10,110,110,1,2,3,4,5,6,7,8,9,10]
for i in range(1,20):
locationPanels = 'locationPanel'+str(k)
locationPanels = wx.Panel(panel1)
label0 = str(k+1)+ '. '+'Panel-1 #############################'
text0 = wx.StaticText(locationPanels, -1, label0)
text0.SetFont(locationFont)
text0.SetForegroundColour('#0101DF')
sizer1.Add(locationPanels, 0, wx.ALL, 5)
sizer1.Add(wx.StaticLine(panel1), 0, wx.ALL|wx.EXPAND, 0)
k += 1
k = 0
availability=[1,2,3,4,5,6,5,4,3,2,1,2,3,110,1,2,3,4,5,6,7,8,9,10]
for i in range(1,20):
sensorPanel ='sensorPanel' +str(k)
sensorPanel = wx.Panel(panel2)
label = str(k)+ '. Panel-2'
text = wx.StaticText(sensorPanel, -1, label)
text.SetForegroundColour('#0101DF')
text.SetFont(locationFont)
sizer2.Add(sensorPanel, 0, wx.ALL, 5)
sizer2.Add(wx.StaticLine(panel2), 0, wx.ALL|wx.EXPAND, 0)
k += 1
panel1.SetSizer(sizer1)
panel2.SetSizer(sizer2)
mainSizer.Add(mainPanel, 15, wx.EXPAND|wx.ALL)
self.SetSizer(mainSizer)
if __name__=='__main__':
app = wx.App()
frame = GUI(parent=None, id=-1, title="Test")
frame.Show()
app.MainLoop()
感谢您的宝贵时间.
推荐答案
当你不带参数调用方法 SetupScrolling 时,两个滚动条都将处于活动状态,如果你不希望 y 轴滚动条显示使用 scroll_y = False.
When you call method SetupScrolling with no parameters both scroll bars will be active, if you dont want the y axis scroll bar showing use scroll_y = False.
panel21 = wx.lib.scrolledpanel.ScrolledPanel(mainPanel, -1, style=wx.SIMPLE_BORDER)
panel21.SetupScrolling(scroll_y = False)
这篇关于使滚动面板的水平滚动条在 wxPython 中永久可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!