1

Okay so, something's odd and I can't figure it out. Suppose I've got some categories, each with some items, all fitted into a dictionary.

import wx
nyoom = {}
nyoom['spiders'] = ['Yellow Sac', 'Orbweaver', 'Garden']
nyoom['cats']= ['Bombay','Angora']
nyoom['cambrian'] = ['Wiwaxia','Hallucigenia','Pikaia','Alomancaris']

Then I want to display each category as a button which collapses or displays all of that category's contents as buttons as well.

class SeqFrame(wx.Frame):
 def __init__(self):
 wx.Frame.__init__( self, None, wx.ID_ANY, "GUI Woes", size=(400,400))
 self.panel = wx.Panel(self, wx.ID_ANY)
 sizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5) #sizer for the window
 numActsTxtBox = wx.TextCtrl( self.panel, -1, "1", size=(40, -1))
 numActsTxtTxt = wx.CheckBox( self.panel, -1, "Number of Times")
 sizer.Add( numActsTxtTxt, 0, wx.ALL )
 sizer.Add( numActsTxtBox, 0, wx.ALL )
 for categories in nyoom.keys():
 self.categPanes=[]
 self.categPanes.append(wx.CollapsiblePane(self.panel, -1, label=categories))
 self.buildPanes(self.categPanes[-1], sizer)
 thisPanel = self.categPanes[-1].GetPane()
 panelSizer = wx.BoxSizer( wx.VERTICAL ) #sizer for the panel contents
 sortedCategory = nyoom[categories]
 sortedCategory.sort()
 for i in range(0,len(nyoom[categories])): 
 thisSeq = wx.Button( thisPanel, label=sortedCategory[i], name=sortedCategory[i])
 panelSizer.Add( thisSeq, 0, wx.GROW | wx.ALL ,0 )
 thisPanel.SetSizer(panelSizer)
 panelSizer.SetSizeHints(thisPanel)
 self.panel.SetSizerAndFit(sizer)
 self.Fit()
 def buildPanes(self, categPane, sizer):
 categPane.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnPaneChanged)
 sizer.Add(categPane, 0, wx.GROW | wx.ALL, 0)
 def OnPaneChanged(self, evt):
 self.panel.GetSizer().Layout()
 self.panel.Fit()
 self.Fit()
if __name__ == '__main__': 
 app = wx.App()
 frame = SeqFrame()
 frame.Show(True)
 app.MainLoop() 

(That's my entire sample app.) I can't figure out why, but everything works fine for the last category in the dictionary: screenshot But the previous categories can only display one button/item.
screenshot 2

asked Apr 4, 2018 at 23:05

1 Answer 1

1

thisPanel is being set inside your loop, but you're calling SetSizer after the loop, so only the last thisPanel gets a sizer. Move the call to SetSizer inside the loop.

answered Apr 5, 2018 at 0:21
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.