am trying to put the radioBox in the center and a button below it, but no matter i try it the radioBox is positioned on top left corner of frame and button doesn't even show! . I don't understand why this is happening
class Panelchoose(wx.Panel):
"""
panel for calculating separately without saving
"""
def __init__(self ,*args, **kw):
super(Panelchoose, self).__init__(*args, **kw)
self.SetBackgroundColour('#48C9B0')
topsizer=wx.BoxSizer(wx.VERTICAL)
radiosizer=wx.BoxSizer(wx.VERTICAL)
btnsizer=wx.BoxSizer(wx.HORIZONTAL)
lblist=['calculationGrid','calculations','xyz2comcat']
self.rbox=wx.RadioBox(self,label="choose from the models below: ",
choices=lblist,majorDimension=3,
style=wx.RA_SPECIFY_ROWS)
btn_next=wx.Button(self ,label=" NEXT ")
#self.Bind(wx.EVT_BUTTON,self.next_, btn_next)
topsizer.Add(self.rbox,0,wx.CENTER|wx.ALIGN_CENTER_VERTICAL,10)
btnsizer.Add(btn_next,0,wx.ALIGN_CENTER_VERTICAL|wx.BOTTOM|wx.EXPAND,5)
topsizer.Add(btnsizer,4,wx.CENTER|wx.BOTTOM,10)
The part your forgot was to tell your panel what its sizer was. If you add self.SetSizer(topsizer)
to the end of your class's __init__
, it will work as you expect.
Here's a full runnable version:
import wx
class Panelchoose(wx.Panel):
"""
panel for calculating separately without saving
"""
def __init__(self ,*args, **kw):
super(Panelchoose, self).__init__(*args, **kw)
self.SetBackgroundColour('#48C9B0')
topsizer=wx.BoxSizer(wx.VERTICAL)
radiosizer=wx.BoxSizer(wx.VERTICAL)
btnsizer=wx.BoxSizer(wx.HORIZONTAL)
lblist=['calculationGrid','calculations','xyz2comcat']
self.rbox=wx.RadioBox(self,label="choose from the models below: ",
choices=lblist,majorDimension=3,
style=wx.RA_SPECIFY_ROWS)
btn_next=wx.Button(self ,label=" NEXT ")
#self.Bind(wx.EVT_BUTTON,self.next_, btn_next)
topsizer.Add(self.rbox,0,wx.CENTER|wx.ALIGN_CENTER_VERTICAL,10)
btnsizer.Add(btn_next,0,wx.ALIGN_CENTER_VERTICAL|wx.BOTTOM|wx.EXPAND,5)
topsizer.Add(btnsizer,0,wx.CENTER|wx.BOTTOM,10)
self.SetSizer(topsizer)
if __name__ == '__main__':
app = wx.App(False)
frame = wx.Frame(None, title='Test')
Panelchoose(parent=frame)
frame.Show()
app.MainLoop()