I can't seem to solve this one by myself.
I have 3 widgets in my wxPython Frame. Two stacked horizontaly and one below them. Here is the code:
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()
As I see it, this should work. And it does... sort of... if i manualy set the size of the panel it will expand and it will look ok. But it should expand automaticaly. i have made a screenshot to see what I am talking about:
You could change these 3 lines:
boxV.Add(boxH1, 0, wx.EXPAND)
boxV.Add(boxH2, 1, wx.EXPAND)
panel1.SetSizerAndFit(boxH1);
SetSizerAndFit let the panel figure out dimensions by itself.