Skip to main content

Checkbox

A Shadcn checkbox.

Example:

shad.Checkbox(
label="Accept terms and conditions",
sublabel="You agree to our Terms of Service and Privacy Policy.",
)
Checkbox
Checkbox

Inherits: LayoutControl

Properties

  • color - The fill color when checked.
  • error_text - An error message shown in red below this checkbox.
  • label - The label shown next to this checkbox.
  • size - The width and height of the checkbox square.
  • sublabel - Secondary text shown below label.
  • unchecked_color - The fill color when unchecked.
  • value - Whether this checkbox is checked.

Events

Example​

Shadcn Checkbox​

play_arrowTry Online
import flet_shadcn_ui as shad

import flet as ft


def main(page: ft.Page):
page.title = "Shadcn Checkbox"

def handle_change(e: ft.Event[shad.Checkbox]):
status.value = "Accepted" if e.control.value else "Not accepted"

status = ft.Text("Not accepted")

page.add(
ft.SafeArea(
content=ft.Column(
controls=[
shad.Checkbox(
label="Accept terms and conditions",
sublabel=(
"You agree to our Terms of Service and Privacy Policy."
),
on_change=handle_change,
),
shad.Checkbox(label="Disabled", value=True, disabled=True),
status,
],
)
)
)


if __name__ == "__main__":
ft.run(main)
checkbox
Accepting the terms

Properties​

colorclass-attributeinstance-attribute​

color: ColorValue | None = None

The fill color when checked.

If None, the primary color of the theme is used.

error_textclass-attributeinstance-attribute​

error_text: str | None = None

An error message shown in red below this checkbox. The box border turns red too.

Set it after validating the value, and set it back to None (or an empty string) to clear the error.

labelclass-attributeinstance-attribute​

label: StrOrControl | None = None

The label shown next to this checkbox.

sizeclass-attributeinstance-attribute​

size: Number | None = None

The width and height of the checkbox square.

If None, defaults to 16.

sublabelclass-attributeinstance-attribute​

sublabel: StrOrControl | None = None

Secondary text shown below label.

unchecked_colorclass-attributeinstance-attribute​

unchecked_color: ColorValue | None = None

The fill color when unchecked.

valueclass-attributeinstance-attribute​

value: bool = False

Whether this checkbox is checked.

Events​

on_changeclass-attributeinstance-attribute​

on_change: ControlEventHandler[Checkbox] | None = None

Called when value changes.

The data property of the event handler argument contains the new value.