Hello all,
I have just started using wxPython to build my GUI. I have encountered a problem creating multiple collapsible panels. I posted an issue to GitHub where a user did help me somewhat. So I posted the code:
“”"
#Creates accordion panels
collapsible_panel1=wx.CollapsiblePane(machineInfo, label=“Machine Info 1”, size=(wx.EXPAND,30))
collapsible_panel2=wx.CollapsiblePane(machineInfo, label=“Machine Info 2”, size=(wx.EXPAND,30))
collapsible_panel3=wx.CollapsiblePane(machineInfo, label=“Machine Info 3”, size=(wx.EXPAND,30))
collapsible_panel4=wx.CollapsiblePane(machineInfo, label=“Machine Info 4”, size=(wx.EXPAND,30))
#Gets panes to put data into them
pane1=collapsible_panel1.GetPane()
pane2=collapsible_panel2.GetPane()
pane3=collapsible_panel3.GetPane()
pane4=collapsible_panel3.GetPane()
#creates sizers for all panes
paneSz1=wx.BoxSizer(wx.VERTICAL)
paneSz2=wx.BoxSizer(wx.VERTICAL)
paneSz3=wx.BoxSizer(wx.VERTICAL)
paneSz4=wx.BoxSizer(wx.VERTICAL)
#self.panel.SetSizerAndFit( machineInfoSizer )
self.Fit()
#Adds accordion panels with some optional spacing
machineInfoSizer.Add(collapsible_panel1,proportion=0)
#machineInfoSizer.AddSpacer(3)
machineInfoSizer.Add(collapsible_panel2,proportion=0)
#machineInfoSizer.AddSpacer(3)
machineInfoSizer.Add(collapsible_panel3,proportion=0)
#machineInfoSizer.AddSpacer(3)
machineInfoSizer.Add(collapsible_panel4, proportion=0)
#machineInfoSizer.AddSpacer(3)
#Add content to panes here
paneSz1.Add(wx.StaticText(pane1, wx.ID_ANY, “test!”), 1, wx.GROW | wx.ALL, 2)
paneSz2.Add(wx.StaticText(pane2, wx.ID_ANY, “test!”), 1, wx.GROW | wx.ALL, 2)
paneSz3.Add(wx.StaticText(pane3, wx.ID_ANY, “test!”), 1, wx.GROW | wx.ALL, 2)
paneSz4.Add(wx.StaticText(pane4, wx.ID_ANY, “test!”), 1, wx.GROW | wx.ALL, 2)
#Sets sizer for all panes
pane1.SetSizer(paneSz1)
pane2.SetSizer(paneSz2)
pane3.SetSizer(paneSz3)
pane4.SetSizer(paneSz4)
#Sets size hints for all panes
paneSz1.SetSizeHints(pane1)
paneSz2.SetSizeHints(pane2)
paneSz3.SetSizeHints(pane3)
paneSz4.SetSizeHints(pane4)
“”"
Which had an issue with me not setting the panes correctly(two grabbed from collapsible pane 3), then at GitHub the guy told me to use this:
for x in range(4 ):
print("Iterating panel: {}".format(x+1 ))
collapsible_panel = wx.CollapsiblePane(self, label="Machine Info {}".format(x+1 ))
machineInfoSizer.Add(collapsible_panel, 0
)
panel = collapsible_panel.GetPane()
psizer = wx.BoxSizer(wx.VERTICAL )
psizer.Add(wx.StaticText(panel, wx.NewId(), "Test {}!".format(x+1)), 1, wx.EXPAND | wx.ALL, 2
)
panel.SetSizer(psizer)
psizer.SetSizeHints(panel)
To keep things straight. Well, this moves the accordions up a bit over some other content. It also appears to disable some of the buttons. Can someone give me some code which will post all accordions with an easy way to update content inside?
Thank you,
TP