Skip to main content

Checkbox

Checkbox allows to select one or more items from a group, or switch between two mutually exclusive options (checked or unchecked, on or off).

Examples​

Live demo

Basic checkboxes​

import pglet
from pglet import Checkbox, Button, Text
with pglet.page("basic-checkboxes") as page:
def button_clicked(e):
t.value = f"Checkboxes values are: {c1.value}, {c2.value}, {c3.value}, {c4.value}."
page.update()

t = Text()
c1 = Checkbox(label='Unchecked by default checkbox', value=False)
c2 = Checkbox(label='Checked by default checkbox', value=True)
c3 = Checkbox(label='Disabled checkbox', disabled=True)
c4 = Checkbox(label="Checkbox with rendered box_side='end'", box_side='end')
b = Button(text='Submit', on_click=button_clicked)
page.add(c1, c2, c3, c4, b, t)

input()

Checkbox with change event​

import pglet
from pglet import Checkbox, Text

with pglet.page("checkbox-with-change-event") as page:
def checkbox_changed(e):
t.value = f"Checkbox value changed to {c.value}"
t.update()

c = Checkbox("Checkbox with 'change' event", on_change=checkbox_changed)
t = Text()

page.add(c, t)
input()

Properties​

NameTypeDefaultDescription
valueboolfalseCurrent value of the checkbox.
labelstringLabel to display next to the checkbox.
boxSidestringstartAllows you to set the checkbox to be at the before (start) or after (end) the label.
focusedboolfalseWhen set to true the focus is set on the control when it's shown on the page or page opened.
datastringAdditional data attached to the control. The value is passed in change event data along with a checkbox state.

Events​

NameDescription
changeFires when the state of checkbox is changed.