Radio Buttons¶
A group of radio buttons offer exclusive choices. Checking one will uncheck all others. All radio buttons in a group must have the same name attribute.
- radio(bind=myfunction, text='mytext', name='mygroup')¶
- Parameters:
bind (function) – The function to be called when the box is checked or unchecked.
text (string) – The text displayed next to the box.
name (string) – Name of the group of radio buttons to which this belongs.
checked (boolean) – If True, the box is checked. Default False.
pos (attribute of canvas) – Location of checkbox. Default is scene.caption_anchor.
disabled (boolean) – If True, the checkbox is grayed out and inactive.
delete() –
mywidget.delete()deletes the widget.
A group of radio buttons that control the color of a sphere:
ball = sphere(color=color.red)
def rfun(evt):
if evt.text is'red':
ball.color=color.red
elif evt.text is 'green':
ball.color=color.green
elif evt.text is 'blue':
ball.color=color.blue
redbutton = radio(bind=rfun, text='red', name='colors', checked=True)
greenbutton = radio(bind=rfun, text='green', name='colors')
bluebutton = radio(bind=rfun, text='blue', name='colors')
Radio Button Event Attributes¶
The argument of the event handler function (‘evt’, in the code above) will have the following attributes (properties of the radio button at the time it was clicked):
evt.textevt.checkedevt.disabled
Additionally, any attributes you have created for the widget (for example, name or id), will be available as attributes of evt.
Accessibility Attributes¶
These attributes support ARIA (Accessible Rich Internet Applications), making widgets usable with screen readers and other assistive technology.
aria_label(string)A text label announced by screen readers when the widget receives focus. Use when there is no visible text that already identifies the widget:
myslider = slider(bind=setspeed, min=0, max=10, aria_label="Speed")
aria_labelledby(wtext)A wtext object whose text serves as the accessible label for this widget. Use when a visible
wtextalready describes the widget:speedlabel = wtext(text="Speed: ") myslider = slider(bind=setspeed, min=0, max=10, aria_labelledby=speedlabel)
aria_describedby(wtext)A wtext object that provides a longer accessible description of the widget, supplementing
aria_labeloraria_labelledby:hint = wtext(text="Drag left or right to set playback speed from 0 to 10") myslider = slider(bind=setspeed, min=0, max=10, aria_label="Speed", aria_describedby=hint)
See also