开发者

wxPython - adding space around a GridBagSizer on a Panel

开发者 https://www.devze.com 2023-03-29 08:23 出处:网络
I have a GridBagSizer (controls) that is placed on a Panel (ctrlPanel) and fitted to it using controls.Fit(ctrlPanel)

I have a GridBagSizer (controls) that is placed on a Panel (ctrlPanel) and fitted to it using

controls.Fit(ctrlPanel)
ctrlPanel.SetSizer(controls)

Now the Panel is placed in a BoxSizer

mainSizer = wx.BoxSizer(wx.VERTICAL)
mainSizer.Add(ctrlPanel, 0, wx.EXPAND|wx.ALL, 10)

However, adding the space around the panel in the box (and not the grid on the Panel) does lead to a "dark grey" border around the panel.

Is there a "lege artis" way to add space around the GridB开发者_运维百科agSizer before it is fitted to the panel? Or do I need to hack empty cells around the filled ones?

Thanks says Woodpicker


I hope that this is what are you looking for:

import wx

class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.panel = wx.Panel(self)
        self.buttons = [wx.Button(self.panel, label=str(n)) for n in range(9)]

        self.sizer = wx.GridBagSizer()
        for i, button in enumerate(self.buttons):
            self.sizer.Add(button, (i / 3, i % 3), flag=wx.ALL | wx.EXPAND)
        self.sizer.AddGrowableCol(1)
        self.sizer.AddGrowableRow(1)

        self.border = wx.BoxSizer()
        self.border.Add(self.sizer, 1, wx.ALL | wx.EXPAND, 20)

        self.panel.SetSizerAndFit(self.border)  
        self.Show()

app = wx.App(False)
win = MainWindow(None)
app.MainLoop()
0

精彩评论

暂无评论...
验证码 换一张
取 消