wxPython: Nesting GridBagSizers not spanning?
I've g0t a GridBagSizer (folderBagSizer)within an existing GridBagSizer (sizer)... now I am trying to populate the nested sizer (folderBagSizer) with some labels. They are showing up UNDER the sizers...?
# Create static box
self.sb_ExtractOptions = wx.StaticBox(panel, label="Options for Extract",
size=(100,100))
folderBoxSizer = wx.GridBagSizer(4, 9)
folderBoxSizer.Add(self.sb_ExtractOptions, pos=(0,0), span=(1,4),
flag=wx.EXPAND, border=10)
# Create the options
label_OptionsCreated = wx.StaticText(panel, label="Created:")
label_OptionsInserted = wx.StaticText(panel, label="Inserted:")
label_Option开发者_运维问答sModified = wx.StaticText(panel, label="Modified:")
# Add them to the sizer (folderBoxSizer)
folderBoxSizer.Add(label_OptionsCreated, pos=(1, 0), flag=wx.LEFT|
wx.ALIGN_CENTER_VERTICAL|wx.TOP, border=3)
folderBoxSizer.Add(label_OptionsInserted, pos=(2, 0), flag=wx.LEFT|
wx.ALIGN_CENTER_VERTICAL|wx.TOP, border=3)
folderBoxSizer.Add(label_OptionsModified, pos=(3, 0), flag=wx.LEFT|
wx.ALIGN_CENTER_VERTICAL|wx.TOP, border=3)
folderBoxSizer.AddGrowableCol(2)
sizer.Add(folderBoxSizer, pos=(2, 0), span=(1,6),flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, border=10)
sizer.AddGrowableCol(2)
panel.SetSizer(sizer)
Thanks in advance. :)
Figured it out, and of course, total noob logic problem.
# Create static box
self.sb_ExtractOptions = wx.StaticBox(panel, label="Options for Extract", size=(100,100))
sbs_ExtractOptions = wx.StaticBoxSizer(self.sb_ExtractOptions, wx.VERTICAL)
OptionBoxSizer = wx.GridBagSizer(4, 9)
# Create the options
logicList = ['<', '<=', '=', '>', '>=']
sizerIndexX = 0
# Created
label_OptionsCreated = wx.StaticText(panel, label="Created:")
combo_LogicalCreated = wx.ComboBox(panel, 1, "", (25, 25), (60, 25), logicList, wx.CB_DROPDOWN)
combo_LogicalCreated.Select(1)
self.tc_DaysAgoCreated = wx.TextCtrl(panel)
label_DaysAgoCreated = wx.StaticText(panel, label="days ago")
# Add them to the sizer (optionBoxSizer)
OptionBoxSizer.Add(label_OptionsCreated, pos=(sizerIndexX, 0), flag=wx.ALL|
wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, border=0)
OptionBoxSizer.Add(combo_LogicalCreated, pos=(sizerIndexX,1), flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=1)
OptionBoxSizer.Add(self.tc_DaysAgoCreated, pos=(sizerIndexX, 2), flag=wx.ALL|
wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, border=0)
OptionBoxSizer.Add(label_DaysAgoCreated, pos=(sizerIndexX,3), flag=wx.ALL|
wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT, border=0)
<snip>
sbs_ExtractOptions.Add(OptionBoxSizer, flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, border=10)
sizer.Add(sbs_ExtractOptions, pos=(2, 0), span=(1,6),flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, border=10)
I was adding the sizer for the static box to the wrong sizer initially -- the way it needs to work is to:
- Create the static box (self.sb_ExtractOptions)
- Create the sizer that will live within it, in this case a StaticBoxSizer. (sbs_ExtractOptions)
- Create the grid for my objects to layout within the sizer (OptionBoxSizer)
- Create GUI elements and add them to OptionBoxSizer
- Add the OptionBoxSizer to the StaticBoxSizer (i.e. add what you did in step 4 to step 2)
- Add the StaticBoxSizer to the panel's main sizer (sizer, in this case)
- Drink a beer, or 5. And celebrate your new lesson like I did in paying freaking attention to what you are doing!
精彩评论