I am trying to use a wxSizer to arrange widgets inside a panel. I can see that widgets are arranged but they do not go inside the frame. Can anyone tell me what I’m doing wrong?
import wx
class MyRegion(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1)
self.panel = wx.Panel(self,-1,pos=(70,200), size=(300,300))
self.panel.SetBackgroundColour((128,128,128)) # dark grey
sizer = wx.BoxSizer(wx.VERTICAL)
b1 = wx.Button(self, label="TEXT1")
b2 = wx.Button(self, label="TEXT2")
b3 = wx.Button(self, label="TEXT3")
sizer.Add(b1)
sizer.Add(b2)
sizer.Add(b3)
self.panel.SetSizer(sizer)
sizer.Fit(self.panel)
if __name__ == "__main__":
app = wx.PySimpleApp()
myRegion = MyRegion()
myRegion.Show()
app.MainLoop()
You should make the panel the parent of buttons instead of the frame.
The reason for this is that although the sizers control the positioning of the items the parent/child relationship in the UI is still controlled by the wx objects that map directly to the underlying OS controls.