我是wxPython的新手,在调整wxPython小部件的维度方面存在一些问题。我正在使用GridBagSizer
并希望延伸我的一些输入。
例如,我想:
self.combo
5列self.input2
5列self.input4
跨10列我尝试使用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()