我正在尝试设置我的 GUI,以便框架自动适合内容,它似乎正在做的是另一种方式并将内容适合框架。
这是常见的吗?我能做些什么吗?
这是我的代码:
panel = wx.Panel(self)
mainSizer = wx.BoxSizer(wx.VERTICAL)
usernameSizer = wx.BoxSizer(wx.HORIZONTAL)
self.usernameBox = wx.TextCtrl(panel, size=(200,35))
usernameText = wx.StaticText(panel, label="\tUsername")
usernameSizer.Add(self.usernameBox, 1)
usernameSizer.Add(usernameText, 1)
passwordSizer = wx.BoxSizer(wx.HORIZONTAL)
self.passwordBox = wx.TextCtrl(panel, size=(200,35))
passwordText = wx.StaticText(panel, label="\tPassword")
passwordSizer.Add(self.passwordBox, 1)
passwordSizer.Add(passwordText, 1)
urlSizer = wx.BoxSizer(wx.HORIZONTAL)
self.urlBox = wx.TextCtrl(panel, size=(200,35))
urlText = wx.StaticText(panel, label='\tFirst chapter URL')
urlSizer.Add(self.urlBox, 1)
urlSizer.Add(urlText, 1)
formatSizer = wx.BoxSizer(wx.HORIZONTAL)
self.formatBox = wx.ComboBox(panel, value='', choices=self.fileFormat, style=wx.CB_READONLY, name="combo", size=(200,35))
formatText = wx.StaticText(panel, label="\tFile format")
formatSizer.Add(self.formatBox, 1)
formatSizer.Add(formatText, 1)
downSizer = wx.BoxSizer(wx.HORIZONTAL)
downButton = wx.Button(panel, label='Download', size=(161,50))
font = wx.Font(20, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
downButton.SetFont(font)
downSizer.Add(downButton, 0, wx.LEFT | wx.TOP, 20)
mainSizer.Add(usernameSizer, 0, wx.LEFT | wx.TOP, 20)
mainSizer.Add(passwordSizer, 0, wx.LEFT | wx.TOP, 20)
mainSizer.Add(urlSizer, 0, wx.LEFT | wx.TOP, 20)
mainSizer.Add(formatSizer, 0, wx.LEFT | wx.TOP, 20)
mainSizer.Add(downSizer, 0, wx.ALIGN_CENTER | wx.BOTTOM, 20)
panel.SetSizer(mainSizer)
panel.Fit()
self.Show(True)
这将所有小部件聚集在顶部,这几乎是我想要的,但下方有很多空白空间,但我不想要。
如果在将大小调整器添加到 mainSizer 时将比例值设置为 1 而不是 0,它会占用整个帧,我怎样才能让帧收缩到内容?