Hi,
I create a frame and a toolbar on it. Then I add a radiobox on toolbar.
But since some of the label strings on the radiobox are longer than the others, I think it sets all labels’ width same according to the longest label. Therefore, the radiobox expands to the right on the toolbar and it doesn’t look good. How do I prevent radiobox from expanding to the right? I would like each label on the radiobox to have minimum width.
Thanks
Best Regards
import wx
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Frame",
style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX,
size=wx.Size(800, 200))
self.toolbar = self.CreateToolBar(True)
item_list = ["Button 1", "Long Label Button 2", "Button 3", "Button 4", "Button 5",]
self.radio_box = wx.RadioBox(self.toolbar, -1, "Box", wx.DefaultPosition, wx.DefaultSize, item_list, 0, wx.RA_SPECIFY_COLS)
self.toolbar.AddSeparator()
self.toolbar.AddControl(self.radio_box)
self.toolbar.Bind(wx.EVT_RADIOBOX, self.EvtRadioBox, self.radio_box)
def EvtRadioBox(self, event):
self.selected_item_ix = self.radio_box.GetSelection()
self.selected_item = self.radio_box.GetString(self.selected_item_ix)
print("selected term: ", self.selected_item)
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()