wxPython输入布局

时间:2015-02-10 06:18:09

标签: python wxpython

我是wxPython的新手,在调整wxPython小部件的维度方面存在一些问题。我正在使用GridBagSizer并希望延伸我的一些输入。

例如,我想:

  1. self.combo 5列
  2. self.input2 5列
  3. self.input4跨10列
  4. 我尝试使用span但失败了...我感谢任何建议!

    import wx
    
    class landing_frame(wx.Frame):
        def __init__(self, parent, title):    
            wx.Frame.__init__(self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size(800, 600), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
            self.font1 = wx.Font(18, wx.DECORATIVE, wx.ITALIC, wx.BOLD) 
            self.InitUI()
            self.Centre()
            self.Show()     
    
        def InitUI(self):
            self.panel = wx.Panel(self)
            self.sizer = wx.GridBagSizer(5, 15)
    
            self.text1 = wx.StaticText(self.panel, label="Welcome!")
            self.sizer.Add(self.text1, pos=(0, 0), flag=wx.TOP|wx.LEFT|wx.BOTTOM, border=15)
    
            line = wx.StaticLine(self.panel)
            self.sizer.Add(line, pos=(1, 0), span=(1, 5), flag=wx.EXPAND|wx.BOTTOM, border=10)
    
            self.text2 = wx.StaticText(self.panel, label="Question 1?")
            self.sizer.Add(self.text2, pos=(2, 0), flag=wx.ALL, border=10)
    
            self.sampleList = ['Op1', 'Op2', 'Op3']
            self.combo = wx.ComboBox(self.panel, 10, choices=self.sampleList)
            self.sizer.Add(self.combo, pos=(2, 1), span=(1, 5), flag=wx.ALL, border=10)
    
            self.input1 = wx.StaticText(self.panel, 11, label="Please Enter Filepath")
            self.sizer.Add(self.input1, pos=(3, 0), span=(1, 1), flag=wx.ALL , border=10)
    
            self.input2 = wx.FilePickerCtrl(self.panel, 12, wx.EmptyString, u"Select a file", u"*.*", wx.DefaultPosition, wx.DefaultSize, wx.FLP_DEFAULT_STYLE )
            self.sizer.Add(self.input2, pos=(3, 1), span=(1, 5), flag=wx.ALL, border=10)
    
            self.input3 = wx.StaticText(self.panel, 13, label="Additional inputs")
            self.sizer.Add(self.input3, pos=(4, 0), flag=wx.ALL , border=10)
    
            self.input4 = wx.TextCtrl(self.panel, 14, 'E.g. ...', wx.DefaultPosition, wx.DefaultSize, 0 )
            self.sizer.Add(self.input4, pos=(4, 1), span=(1, 10), flag=wx.ALL, border=10)
    
            self.panel.SetSizer(self.sizer)
    
    if __name__ == '__main__':
        app = wx.App(redirect=False, filename="mylogfile.txt")
        landing_frame(None, title="Test")
        app.MainLoop()
    

0 个答案:

没有答案