Checkboxes¶
A checkbox is a widget that has two states: selected and not selected.
- checkbox(bind=myfunction, text='mytext')¶
- Parameters:
bind (function) – The function to be called when the box is checked or unchecked.
text (string) – The text displayed next to the box.
checked (boolean) – If True, the box is checked.
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 checkbox that controls the rotation of a cube:
cube = box(color=color.orange)
spin = True
def rotate(evt):
global spin
if evt.checked:
spin=True
else:
spin=False
rcheck = checkbox( bind=rotate, text='Spin', checked=True)
while True:
rate(20)
if spin:
cube.rotate(angle=pi/20, axis=vec(0,1,0))
else:
pass
Checkbox Event Attributes¶
The argument of the event handler function (‘evt’, in the code above) will have the following attributes (properties of the checkbox 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