import wx

class AddTestApp(wx.App):
    def OnInit(self):
        wx.InitAllImageHandlers()
        # Create the frame
        frame = wx.Frame(None,-1,'',style=wx.DEFAULT_FRAME_STYLE)
        self.SetTopWindow(frame)
        # Add a sizer to it
        mainsizer = wx.BoxSizer(wx.VERTICAL)
        # Create a collapsible with a button and a sizer for it 
        self.collapsible = collapsible = wx.CollapsiblePane(frame, label="Expand me",style=wx.ALL|wx.GROW)
        csizer = wx.BoxSizer(wx.VERTICAL)
        pane = collapsible.GetPane()
        b = wx.Button(pane,label="Click me")
        frame.Bind(wx.EVT_BUTTON,self.OnAddButtonPressed,b)
        csizer.Add(b)
        pane.SetSizer(csizer)
        # Add the collapsible to the main sizer
        mainsizer.Add(collapsible,0)
        # Set the mainsizer as the frame sizer
        frame.SetSizer(mainsizer)
        
        # Do the layout
        frame.Layout()
        mainsizer.Fit(frame)
        frame.Show()

        return 1
    
    def OnAddButtonPressed(self,event):
        # Add another button to the collapsible
        pane = self.collapsible.GetPane()
        b = wx.Button(pane,label="A new button")
        pane.GetSizer().Add(b)
        pane.Layout()
       
if __name__=='__main__':
    # Create the app
    app = AddTestApp(0)
    # run
    app.MainLoop()