OpenSesame videos
Python videos

Checkbox functions

class checkbox

The checkbox widget is a checkable box accompanied by a string of text.

Example (OpenSesame script):

widget 0 0 1 1 checkbox group="group" text="Option 1"
widget 0 1 1 1 checkbox group="group" text="Option 2"

Example (Python):

from libopensesame import widgets
form = widgets.form(exp)
checkbox1 = widgets.checkbox(form, text='Option 1', group='group')
checkbox2 = widgets.checkbox(form, text='Option 2', group='group')
form.set_widget(checkbox1, (0,0))
form.set_widget(checkbox2, (0,1))

function checkbox.__init__(form, text=u'checkbox', frame=False, group=None, checked=False, click_accepts=False, var=None)

Constructor.

Arguments:

  • form -- The parent form.
    • Type: form

Keywords:

  • text -- Checkbox text.
    • Type: str, unicode
    • Default: 'checkbox'
  • frame -- Indicates whether a frame should be drawn around the widget.
    • Type: bool
    • Default: False
  • group -- If a group is specified, checking one checkbox from the group will uncheck all other checkboxes in that group. Checkboxes that are part of a group cannot be unchecked, except by clicking on another checkbox in the group. The group keyword also affects how variables are stored (see the var keyword).
    • Type: str, unicode, NoneType
    • Default: None
  • checked -- The initial checked state of the checkbox.
    • Type: bool
    • Default: False
  • click_accepts -- Indicates whether a click press should accept and close the form.
    • Type: bool
    • Default: False
  • var -- The name of the experimental variable that should be used to log the widget status. This variable will contain a semi-colon separated list of the text of all checked checkboxes in the same group, or 'no' if no checkbox in the group is checked. For the purpose of the variable, all checkboxes that are not part of a group are placed in the same group. For more information about the use of response variables in forms, see the form docu

function checkbox.draw_frame(rect=None, style=u'normal')

Draws a simple frame around the widget.

Keywords:

  • rect -- A (left, top, width, height) tuple for the frame geometry or None to use the widget geometry.
    • Type: tuple, NoneType
    • Default: None
  • style -- A visual style. Should be 'normal', 'active', or 'light'.
    • Type: str, unicode
    • Default: 'normal'

function checkbox.draw_text(text, html=True)

Draws text inside the widget.

Arguments:

  • text -- The text to draw.
    • Type: str, unicode

Keywords:

  • html -- Indicates whether HTML should be parsed.
    • Type: bool
    • Default: True

function checkbox.on_mouse_click(pos)

Is called whenever the user clicks on the widget. Toggles the state of the checkbox.

Arguments:

  • pos -- An (x, y) coordinate tuple.
    • Type: tuple

function checkbox.render()

Draws the widget.

function checkbox.set_checked(checked=True)

Sets the checked status of the checkbox.

Keywords:

  • checked -- The checked status.
    • Type: bool
    • Default: True

function checkbox.set_rect(rect)

Sets the widget geometry.

Arguments:

  • rect -- A (left, top, width, height) tuple.
    • Type: tuple

function checkbox.set_var(val, var=None)

Sets an experimental variable.

Arguments:

  • val -- A value.
    • Type: str, unicode

Keywords:

  • var -- A variable name, or None to use widget default.
    • Type: str, unicode, NoneType
    • Default: None
Supported by Supported by