Reputation: 5315
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.
Problem:
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.
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?
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()
Thank you for your time.
Upvotes: 2
Views: 1631
Reputation: 3625
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)
Upvotes: 1