使用wxpython在面板中构建窗口小部件的位置

时间:2017-06-08 08:31:23

标签: python python-2.7 wxpython boxsizer

我试图将radioBox放在中间并在它下面放一个按钮,但不管我试一试,radioBox位于框架的左上角,按钮甚至不显示! 。 我不明白为什么会发生这种情况

class Panelchoose(wx.Panel):
    """
     panel for calculating separately without saving
    """
    def __init__(self ,*args, **kw):
        super(Panelchoose, self).__init__(*args, **kw)
        self.SetBackgroundColour('#48C9B0')
        topsizer=wx.BoxSizer(wx.VERTICAL)
        radiosizer=wx.BoxSizer(wx.VERTICAL)
        btnsizer=wx.BoxSizer(wx.HORIZONTAL)

        lblist=['calculationGrid','calculations','xyz2comcat']
        self.rbox=wx.RadioBox(self,label="choose from the models below:   ",
                              choices=lblist,majorDimension=3,
                              style=wx.RA_SPECIFY_ROWS)


        btn_next=wx.Button(self ,label=" NEXT  ")
        #self.Bind(wx.EVT_BUTTON,self.next_, btn_next)

        topsizer.Add(self.rbox,0,wx.CENTER|wx.ALIGN_CENTER_VERTICAL,10)
        btnsizer.Add(btn_next,0,wx.ALIGN_CENTER_VERTICAL|wx.BOTTOM|wx.EXPAND,5)

        topsizer.Add(btnsizer,4,wx.CENTER|wx.BOTTOM,10)

1 个答案:

答案 0 :(得分:0)

你忘记的部分是告诉你的小组它的大小是什么。如果您将self.SetSizer(topsizer)添加到班级__init__的末尾,它将按您的预期运作。

这是一个完整的可运行版本:

import wx


class Panelchoose(wx.Panel):
    """
     panel for calculating separately without saving
    """
    def __init__(self ,*args, **kw):
        super(Panelchoose, self).__init__(*args, **kw)
        self.SetBackgroundColour('#48C9B0')
        topsizer=wx.BoxSizer(wx.VERTICAL)
        radiosizer=wx.BoxSizer(wx.VERTICAL)
        btnsizer=wx.BoxSizer(wx.HORIZONTAL)

        lblist=['calculationGrid','calculations','xyz2comcat']
        self.rbox=wx.RadioBox(self,label="choose from the models below:   ",
                              choices=lblist,majorDimension=3,
                              style=wx.RA_SPECIFY_ROWS)


        btn_next=wx.Button(self ,label=" NEXT  ")
        #self.Bind(wx.EVT_BUTTON,self.next_, btn_next)

        topsizer.Add(self.rbox,0,wx.CENTER|wx.ALIGN_CENTER_VERTICAL,10)
        btnsizer.Add(btn_next,0,wx.ALIGN_CENTER_VERTICAL|wx.BOTTOM|wx.EXPAND,5)

        topsizer.Add(btnsizer,0,wx.CENTER|wx.BOTTOM,10)

        self.SetSizer(topsizer)

if __name__ == '__main__':
    app = wx.App(False)
    frame = wx.Frame(None, title='Test')
    Panelchoose(parent=frame)
    frame.Show()
    app.MainLoop()