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.
Syntax:
wx.RadioBox.RadioBox( parent, id=ID_ANY, label=””, pos=DefaultPosition,
size=DefaultSize, choices=[], majorDimension=0, style=RA_SPECIFY_COLS,
validator=DefaultValidator, name=RadioBoxNameStr )
Parameters:
Parameter | Input Type | Description |
---|
parent | wx.Window | Parent window. Should not be None. |
id | wx.WindowID | Control identifier. A value of -1 denotes a default value. |
label | string | Text Label. |
pos | wx.Point | Window position. |
size | wx.Window | Window size. |
choices | list of strings | Window style. |
majorDimension | int | Specifies 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. |
style | long | An array of choices with which to initialize the radiobox. |
validator | wx.Validator | Window validator. |
name | string | Window name. |
Code Example:
import wx
class FrameUI(wx.Frame):
def __init__( self , parent, title):
super (, self ).__init__(parent, title = title, size = ( 300 , 200 ))
self .InitUI()
def InitUI( self ):
pnl = wx.Panel( self )
lblList = [ 'Value X' , 'Value Y' , 'Value Z' ]
self .rbox = wx.RadioBox(pnl, label = 'RadioBox' , pos = ( 80 , 10 ), choices = lblList,
majorDimension = 1 , style = wx.RA_SPECIFY_ROWS)
self .Centre()
self .SetSize(( 400 , 250 ))
self .Show( True )
ex = wx.App()
FrameUI( None , 'RadioButton and RadioBox' )
ex.MainLoop()
|
Output Window:
