我有一个 wx.Panel,它有一个与之关联的 GridBagSizer。这个面板被放置在另一个 Sizer (BoxSizer) 中,它的 add 有 expand 标志——这意味着面板占据了 sizer 的整个宽度,这很棒。...但是面板的内部尺寸器现在没有填满面板。
当我添加它的组件时,我尝试将内部sizer 的标志设置为 wx.Expand|wx.ALL,但这不起作用。任何人都知道如何确保在面板展开时大小调整器保持与面板相同的宽度?
编辑:我的代码创建包含 GridBagSizer 的面板:
def getNewButton(self, bmp1, bmp2, label):
panel = wx.Panel(self.frame, -1, pos=(0,0), style=wx.BORDER_THEME)
sizer = wx.GridBagSizer(0, 1)
#The button
b = buttons.GenBitmapToggleButton(panel, wx.ID_ANY, None)
self.frame.Bind(wx.EVT_BUTTON, self.OnToggleButton, b)
b.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
b.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
mask = wx.Mask(bmp1, wx.BLUE)
bmp1.SetMask(mask)
b.SetBitmapLabel(bmp1)
mask = wx.Mask(bmp2, wx.BLUE)
bmp2.SetMask(mask)
b.SetBitmapSelected(bmp2)
b.SetToggle(False)
b.SetInitialSize(size = wx.Size(30, 30))
b.SetBezelWidth(0)
#The Label Button
l1 = buttons.GenButton(panel, wx.ID_ANY, label, style=wx.BORDER_NONE)
self.frame.Bind(wx.EVT_BUTTON, self.OnFlatButton, l1)
l1.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter)
l1.Bind(wx.EVT_LEAVE_WINDOW, self.OnNonToggleMouseLeave)
sizer.Add(b, wx.GBPosition(0,0))
sizer.Add(l1, wx.GBPosition(0,1), flag=wx.EXPAND)
panel.SetSizer(sizer)
sizer.SetSizeHints(panel)
self.buttonsList.append(ImgToggleButtonComponents(b,panel,l1))
return panel