我有下面的示例应用程序,其中有几个简单的大小调整器,由于某种原因,它们垂直居中,这是我不想要的(请参阅附件)。我希望 wxchoice sizer 位于窗口的顶部,而不是垂直的中间,即使调整窗口大小时,它也保持在那个位置,但我就是找不到答案。
import wx
class Mywin(wx.Frame):
def __init__(self, parent, id, title):
super(Mywin, self).__init__(parent, title=title)
self.panel = wx.Panel(self)
self.vbox = wx.BoxSizer(wx.VERTICAL)
nm = wx.StaticBox(self.panel, -1, 'Drop List:')
nmSizer = wx.StaticBoxSizer(nm, wx.VERTICAL)
self.workflowList = ["choice 1", "choice 2"]
nmbox = wx.BoxSizer(wx.HORIZONTAL)
self.workflowChoice = wx.Choice(self.panel, choices=self.workflowList)
self.vbox.Add(nmSizer, 0, wx.ALL | wx.EXPAND, 0)
nmbox.Add(self.workflowChoice, 0, wx.ALL, 5)
nmSizer.Add(nmbox, 0, wx.ALL, 5)
self.btnSizer = wx.BoxSizer(wx.HORIZONTAL)
self.buttonGo = wx.Button(self.panel, -1, "Go")
self.buttonClose = wx.Button(self.panel, -1, "Quit")
self.btnSizer.Add(self.buttonGo, 0, wx.ALL, 5)
self.btnSizer.Add(self.buttonClose, 0, wx.ALL, 5)
self.vbox.Add(nmSizer, 0, wx.ALL | wx.CENTER | wx.TOP, 5)
self.vbox.Add(self.btnSizer, 0, wx.ALL | wx.CENTER, 5)
self.panel.SetSizer(self.vbox)
self.panel.Fit()
self.Show()
app = wx.App()
Mywin(None, -1, 'Test App ')
app.MainLoop()
您正在将 StaticBox 添加到 StaticBoxSizer,因此它的内裤可能会发生变化。
尝试以下方法:
import wx
class Mywin(wx.Frame):
def __init__(self, parent, id, title):
super(Mywin, self).__init__(parent, id=id, title=title)
self.panel = wx.Panel(self)
self.vbox = wx.BoxSizer(wx.VERTICAL)
nm = wx.StaticBoxSizer(wx.VERTICAL, self.panel, 'Drop List:')
self.workflowList = ["choice 1", "choice 2"]
self.workflowChoice = wx.Choice(self.panel, choices=self.workflowList)
nm.Add(self.workflowChoice, 0, wx.ALL|wx.EXPAND, 5)
self.vbox.Add(nm, 0, wx.ALL, 5) # Add the box to the sizer
self.btnSizer = wx.BoxSizer(wx.HORIZONTAL)
self.buttonGo = wx.Button(self.panel, -1, "Go")
self.buttonClose = wx.Button(self.panel, -1, "Quit")
self.btnSizer.Add(self.buttonGo, 0, wx.ALL, 5)
self.btnSizer.Add(self.buttonClose, 0, wx.ALL, 5)
self.vbox.Add(self.btnSizer, 0, wx.ALL|wx.EXPAND, 0)
self.panel.SetSizer(self.vbox)
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.buttonClose.Bind(wx.EVT_BUTTON, self.OnClose)
self.Show()
def OnClose(self, event):
self.Destroy()
app = wx.App()
Mywin(None, -1, 'Test App ')
app.MainLoop()