Need wx.lib.scrolledpanel.ScrolledPanel Help (with Sample!)

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()

Hi,

shari@loralee.net wrote:

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!
  

I attach the changed code, it works for me on:
# Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)]
# wxPython 2.8.9.1, Boa Constructor 0.6.1

- problem was mainly in OnAddButton, when adding a control to a sizer you just need to call the sizers.Layout() method, or the one of the parent. And you should not use SetSizer again and again.

Werner

spanelsample.py (1.53 KB)