Open In App
Related Articles

wxPython – Create RadioBox in frame

Improve Article
Save Article
Like Article

In this article we are going to learn to create a radio box in a frame. A radio box item is used to select one of number of mutually exclusive choices. It is displayed as a vertical column or horizontal row of labeled buttons.

In order to create radio box we will use RadioBox() constructor in wx.RadioBox class of wxPython.

wx.RadioBox.RadioBox( parent, id=ID_ANY, label=””, pos=DefaultPosition,
size=DefaultSize, choices=[], majorDimension=0, style=RA_SPECIFY_COLS,
validator=DefaultValidator, name=RadioBoxNameStr )


ParameterInput TypeDescription
parentwx.WindowParent window. Should not be None.
idwx.WindowIDControl identifier. A value of -1 denotes a default value.
labelstringText Label.
poswx.PointWindow position.
sizewx.WindowWindow size.
choiceslist of stringsWindow style.
majorDimensionintSpecifies the maximum number of rows (if style contains RA_SPECIFY_ROWS ) or columns (if style contains RA_SPECIFY_COLS ) for a two-dimensional radiobox. The default value of 0 means to use the number of items, i.e. number of elements in choices.
stylelongAn array of choices with which to initialize the radiobox.
validatorwx.ValidatorWindow validator.
namestringWindow name.

Code Example:

import wx
class FrameUI(wx.Frame):
    def __init__(self, parent, title):
        super(, self).__init__(parent, title = title, size =(300, 200))
        # function for in-frame components
    def InitUI(self):
        # parent panel for radio box
        pnl = wx.Panel(self)
        # list of choices
        lblList = ['Value X', 'Value Y', 'Value Z']
        # create radio box containing above list
        self.rbox = wx.RadioBox(pnl, label ='RadioBox', pos =(80, 10), choices = lblList,
                                majorDimension = 1, style = wx.RA_SPECIFY_ROWS)
        # set frame in centre
        # set size of frame
        self.SetSize((400, 250))
        # show output frame
# wx App instance
ex = wx.App()
# Example instance
FrameUI(None, 'RadioButton and RadioBox')

Output Window:

Last Updated : 29 Jun, 2020
Like Article
Save Article
Similar Reads
Related Tutorials