I don’t know of a way to space the buttons inside a radio box, but I had a go at putting radio buttons inside a StaticBoxSizer
which seems to work (on linux at least).
The code below creates two StaticBoxSizers each containing 4 radio buttons. The buttons inside a box sizer act like a radio box in that only one of them can be selected at any instance. The selection in one box sizer does not affect the selection in the other box sizer.
In the top box sizer, the radio buttons themselves are stretched. This means that, if you click on the space in the box sizer it will select the radio button to its left.
In the bottom box sizer, there are stretchable spacers around each radio button, so you have to click on the radio buttons themselves, not the spacers.
See which style you prefer.
Of course you can’t use EVT_RADIOBOX, but will have to bind EVT_RADIOBUTTON for each radio button to an appropriate handler.
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
wx.Frame.__init__(self, *args, **kwds)
self.SetSize((450, 200))
self.SetTitle("Expanding 'RadioBoxes'")
self.panel_1 = wx.Panel(self, wx.ID_ANY)
sizer_1 = wx.BoxSizer(wx.VERTICAL)
# Top 'radio box' with stretched radio buttons
self.panel_2 = wx.Panel(self.panel_1, wx.ID_ANY)
sizer_1.Add(self.panel_2, 0, wx.EXPAND, 0)
sizer_2 = wx.StaticBoxSizer(wx.StaticBox(self.panel_2, wx.ID_ANY, "Stretched Radio Buttons"), wx.HORIZONTAL)
self.radio_btn_1 = wx.RadioButton(sizer_2.GetStaticBox(), wx.ID_ANY, "One", style=wx.RB_GROUP)
sizer_2.Add(self.radio_btn_1, 1, 0, 0)
self.radio_btn_2 = wx.RadioButton(sizer_2.GetStaticBox(), wx.ID_ANY, "Two")
sizer_2.Add(self.radio_btn_2, 1, 0, 0)
self.radio_btn_3 = wx.RadioButton(sizer_2.GetStaticBox(), wx.ID_ANY, "Three")
sizer_2.Add(self.radio_btn_3, 1, 0, 0)
self.radio_btn_4 = wx.RadioButton(sizer_2.GetStaticBox(), wx.ID_ANY, "Four")
sizer_2.Add(self.radio_btn_4, 1, 0, 0)
# Bottom 'radio box' with expanding spacers
self.panel_3 = wx.Panel(self.panel_1, wx.ID_ANY)
sizer_1.Add(self.panel_3, 0, wx.EXPAND | wx.TOP, 25)
sizer_3 = wx.StaticBoxSizer(wx.StaticBox(self.panel_3, wx.ID_ANY, "Spaced Radio Buttons"), wx.HORIZONTAL)
sizer_3.Add((20, 20), 1, 0, 0)
self.radio_btn_5 = wx.RadioButton(sizer_3.GetStaticBox(), wx.ID_ANY, "One", style=wx.RB_GROUP)
sizer_3.Add(self.radio_btn_5, 0, 0, 0)
sizer_3.Add((20, 20), 1, 0, 0)
self.radio_btn_6 = wx.RadioButton(sizer_3.GetStaticBox(), wx.ID_ANY, "Two")
sizer_3.Add(self.radio_btn_6, 0, 0, 0)
sizer_3.Add((20, 20), 1, 0, 0)
self.radio_btn_7 = wx.RadioButton(sizer_3.GetStaticBox(), wx.ID_ANY, "Three")
sizer_3.Add(self.radio_btn_7, 0, 0, 0)
sizer_3.Add((20, 20), 1, 0, 0)
self.radio_btn_8 = wx.RadioButton(sizer_3.GetStaticBox(), wx.ID_ANY, "Four")
sizer_3.Add(self.radio_btn_8, 0, 0, 0)
sizer_3.Add((20, 20), 1, 0, 0)
self.panel_3.SetSizer(sizer_3)
self.panel_2.SetSizer(sizer_2)
self.panel_1.SetSizer(sizer_1)
self.Layout()
if __name__ == "__main__":
app = wx.App()
frame = MyFrame(None)
frame.Show()
app.MainLoop()