Checkboxes

_images/checkbox.png

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.text

  • evt.checked

  • evt.disabled

Additionally, any attributes you have created for the widget (for example, name or id), will be available as attributes of evt.