默认情况下,wxPython小部件间隔不正确

时间:2017-02-23 20:56:01

标签: python wxpython

我在wxPython中间隔小部件时遇到问题。

在下面的代码中,默认情况下Vbox2和Vbox3中的按钮被压缩,我不明白为什么。我认为BoxSizer默认情况下应该扩展以适应其所有内容。

我的问题是:我需要改变什么以防止这种按钮拥挤?

以下是运行我的示例的完整代码:

import wx
import sys


class GridFrame(wx.Frame):

    def __init__(self, frame_name="grid frame",
                 panel_name="grid panel", parent=None):
        title = 'Edit {} data'.format(panel_name)
        super(GridFrame, self).__init__(parent=parent, id=wx.ID_ANY,
                                        name=frame_name, title=title)
        self.remove_cols_mode = False
        self.panel = wx.Panel(self, name=panel_name)#, size=wx.GetDisplaySize())
        self.grid_type = str(panel_name)
        self.InitUI()


    ## Initialization functions
    def InitUI(self):
        """
        initialize window
        """
        self.main_sizer = wx.BoxSizer(wx.VERTICAL)
        set1, set2, set3 = [], [], []
        ## btns set 1
        for btn_name in ['btn1', 'btn1a']:
            btn = wx.Button(self.panel, label=btn_name, name=btn_name)
            set1.append((btn))
        ## Btns set 2
        for btn_name in ['btn2', 'btn3', 'btn4']:
            btn = wx.Button(self.panel, label=btn_name, name=btn_name)
            set2.append((btn))
        ## btns set 3
        for btn_name in ['btn5', 'btn6', 'btn7']:
            btn = wx.Button(self.panel, label=btn_name, name=btn_name)
            set3.append((btn))

        ## Add content to sizers
        self.hbox = wx.BoxSizer(wx.HORIZONTAL)
        vbox1 = wx.StaticBoxSizer(wx.StaticBox(self.panel, -1, label='Vbox1'), wx.VERTICAL)
        vbox2 = wx.StaticBoxSizer(wx.StaticBox(self.panel, -1, label='Vbox2'), wx.VERTICAL)
        vbox3 = wx.StaticBoxSizer(wx.StaticBox(self.panel, -1, label='Vbox3'), wx.VERTICAL)
        for btn in set1:
            vbox1.Add(btn, flag=wx.ALL, border=5)
        for btn in set2:
            vbox2.Add(btn, flag=wx.ALL, border=5)
        for btn in set3:
            vbox3.Add(btn, flag=wx.ALL, border=5)
        self.hbox.Add(vbox1, flag=wx.ALL, border=5)
        self.hbox.Add(vbox2, flag=wx.ALL, border=5)
        self.hbox.Add(vbox3, flag=wx.ALL, border=5)

        # final layout, set size
        self.main_sizer.Add(self.hbox, flag=wx.ALL|wx.ALIGN_CENTER|wx.SHAPED, border=20)
        self.main_sizer.AddSpacer(20)
        self.panel.SetSizer(self.main_sizer)
        self.panel_sizer = wx.BoxSizer(wx.VERTICAL)
        self.panel_sizer.Add(self.panel, 1)
        self.SetSizer(self.panel_sizer)
        self.panel_sizer.Fit(self)
        self.Centre()
        self.Show()


if __name__ == "__main__":
    app = wx.App()
    frame = GridFrame()
    if '-i' in sys.argv:
        import wx.lib.inspection
        wx.lib.inspection.InspectionTool().Show()
    app.MainLoop()

0 个答案:

没有答案