我有一個與它關聯的GridBagSizer的wx.Panel。該面板放置在另一個Sizer(BoxSizer)中,其添加了擴展標誌 - 意味着面板佔據了sizer的全部寬度,這非常棒。 ...但現在面板的內部尺寸不會填滿面板。當面板在另一個wx.sizer中展開時,如何展開wx.panel的wx.sizer?
我試着將內部sizer的標誌設置爲wx.Expand | wx.ALL,當我添加它的組件時,但沒有奏效。任何人都知道如何確保sizer在擴展面板時保持與面板相同的寬度?
編輯:我的代碼,創建一個包含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
試過sizerHints,但沒有運氣,我放置它們,所以我發佈了實際創建面板的方法,它的sizer – Fry 2009-03-04 18:02:19