I'm trying to set up a scrolled panel that gets buttons added to it. When
the buttons get too large the area, the panel should add scroll bars.
Unfortunately, I must be doing something wrong in the way I set up and use
the scrolled panel, because the scrollbars never appear. Here is a sample
app that demonstrates the problem. The "Add Button" button needs to be
clicked several times to show that the buttons added will run off the side
of the panel.
My wxPython version is: 2.8.9.1 (gtk2-unicode)
Any help would be appreciated!
Thanks,
Shari
Sample application below:
#!/bin/env python
import wx
import wx.lib.scrolledpanel as scrolled
import wx.lib.inspection
class MyFrame(wx.Frame):
buttonCount = 0
def __init__(self):
wx.Frame.__init__(self, None, - 1, "My Frame", size=(300, 300))
panel = wx.Panel(self, - 1)
button = wx.Button(panel, label="Add button", pos=wx.DefaultPosition,
size=wx.DefaultSize)
self.Bind(wx.EVT_BUTTON, self.OnAddButton, button)
self.scrolledPanel = scrolled.ScrolledPanel(panel, - 1,
size=wx.DefaultSize)
self.scrollPanelSizer = wx.BoxSizer(wx.HORIZONTAL)
self.scrolledPanel.SetSizer(self.scrollPanelSizer)
self.scrollPanelSizer.Fit(self)
self.scrolledPanel.SetupScrolling(scroll_x=True, scroll_y=False)
self.FitInside()
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(button)
sizer.Add(self.scrolledPanel)
panel.SetSizer(sizer)
panel.Fit()
def OnAddButton(self, event):
self.buttonCount = self.buttonCount + 1
print "Add button clicked: ", self.buttonCount
button = wx.Button(self.scrolledPanel,
label="Button " + str(self.buttonCount),
pos=(0, 0), size=wx.DefaultSize)
self.scrollPanelSizer.Add(button, 0, wx.ALL, 1)
self.scrollPanelSizer.Fit(self.scrolledPanel)
self.SetSizer(self.scrollPanelSizer)
self.scrolledPanel.SetupScrolling(scroll_x=True, scroll_y=False)
self.scrolledPanel.FitInside()
if __name__ == '__main__':
print wx.version()
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show(True)
wx.lib.inspection.InspectionTool().Show()
app.MainLoop()