我似乎无法自己解决这个问题。
我的 wxPython 框架中有 3 个小部件。两个水平堆叠,一个在它们下方。这是代码:
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id=wx.ID_ANY, title="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name="MyFrame"):
super(MyFrame, self).__init__(parent, id, title, pos, size, style, name)
panel1 = wx.Panel(self, -1)
boxV = wx.BoxSizer(wx.VERTICAL)
boxH1 = wx.BoxSizer(wx.HORIZONTAL)
boxH2 = wx.BoxSizer(wx.HORIZONTAL)
combo = wx.ComboBox(panel1, -1, size=(200, -1), choices=['A', 'B', 'C'], style=wx.CB_READONLY, value="Izberite COM vrata")
button = wx.Button(panel1, -1, size=(100, -1), label="Connect")
boxH1.Add(combo, 1, wx.ALL, 10);
boxH1.Add(button, 1, wx.ALL, 10)
boxH2.Add(wx.TextCtrl(self, -1), 1, wx.EXPAND)
boxV.Add(boxH1, 0)
boxV.Add(boxH2, 1, wx.EXPAND)
panel1.SetSizer(boxH1);
self.SetSizer(boxV);
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, title="Simulation")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
if __name__ == '__main__':
app = MyApp(0)
app.MainLoop()
如我所见,这应该可行。它确实......有点......如果我手动设置面板的大小,它会扩展并且看起来没问题。但它应该会自动扩展。我做了一个截图来看看我在说什么: