我似乎无法独自解决这个问题。
我的wxPython Frame中有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()
我认为,这应该有效。它确实...有点......如果我手动设置面板的大小它会扩展它看起来不错。但它应该自动扩展。我制作了截图,看看我在说什么:
答案 0 :(得分:0)
您可以更改以下3行:
boxV.Add(boxH1, 0, wx.EXPAND)
boxV.Add(boxH2, 1, wx.EXPAND)
panel1.SetSizerAndFit(boxH1);
SetSizerAndFit让面板自行计算尺寸。