wxPython - Create Radio Box with Items in different orientation

wxPython - Create Radio Box with Items in different orientation

In wxPython, a wx.RadioBox provides a way to present a user with a choice between a few mutually exclusive choices. The wx.RadioBox widget displays a list or a table of choices, of which only one can be selected at a time.

When creating a wx.RadioBox, you can specify its orientation (either vertical or horizontal) using the style parameter. The options are wx.RA_SPECIFY_COLS for horizontal orientation and wx.RA_SPECIFY_ROWS for vertical orientation.

Here's an example that shows how to create a wx.RadioBox with both orientations:

import wx class MyFrame(wx.Frame): def __init__(self, parent, title): super(MyFrame, self).__init__(parent, title=title, size=(400, 300)) panel = wx.Panel(self) sizer = wx.BoxSizer(wx.VERTICAL) # Vertical orientation self.radio_box_vertical = wx.RadioBox(panel, label="Vertical Choices", choices=["Choice 1", "Choice 2", "Choice 3"], majorDimension=1, style=wx.RA_SPECIFY_ROWS) sizer.Add(self.radio_box_vertical, 0, wx.ALL | wx.EXPAND, 5) # Horizontal orientation self.radio_box_horizontal = wx.RadioBox(panel, label="Horizontal Choices", choices=["Choice A", "Choice B", "Choice C"], majorDimension=3, style=wx.RA_SPECIFY_COLS) sizer.Add(self.radio_box_horizontal, 0, wx.ALL | wx.EXPAND, 5) panel.SetSizer(sizer) self.Show() if __name__ == "__main__": app = wx.App(False) frame = MyFrame(None, "wx.RadioBox Orientation Demo") app.MainLoop() 

In this example, the wx.RadioBox with vertical orientation displays choices in a column, while the one with horizontal orientation displays choices in a row. Adjust the majorDimension parameter to modify the number of rows or columns depending on the orientation.


More Tags

localdate restart windows-console server-sent-events for-loop exit google-sheets-export-url csrf-protection spring-hateoas pdftk

More Programming Guides

Other Guides

More Programming Examples