Skip to main content

RadioGroup

A Shadcn radio group: a set of options where only one can be selected.

Example:

shad.RadioGroup(
value="comfortable",
items=[
shad.Radio(value="default", label="Default"),
shad.Radio(value="comfortable", label="Comfortable"),
shad.Radio(value="compact", label="Compact"),
],
)
RadioGroup
RadioGroup

Inherits: LayoutControl

Properties

Events

  • on_change - Called when the selected option changes.

Example​

Shadcn RadioGroup​

play_arrowTry Online
import flet_shadcn_ui as shad

import flet as ft


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

def handle_change(e: ft.Event[shad.RadioGroup]):
selection.value = f"Spacing: {e.control.value}"

selection = ft.Text("Spacing: comfortable")

page.add(
ft.SafeArea(
content=ft.Column(
spacing=16,
controls=[
shad.RadioGroup(
value="comfortable",
on_change=handle_change,
items=[
shad.Radio(value="default", label="Default"),
shad.Radio(value="comfortable", label="Comfortable"),
shad.Radio(
value="compact",
label="Compact",
sublabel="Fits more rows on screen.",
),
],
),
selection,
],
)
)
)


if __name__ == "__main__":
ft.run(main)
radio_group
Choosing Compact

Properties​

descriptionclass-attributeinstance-attribute​

description: StrOrControl | None = None

Helper text shown below this group.

error_textclass-attributeinstance-attribute​

error_text: str | None = None

An error message shown in red below this group.

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

horizontalclass-attributeinstance-attribute​

horizontal: bool = False

Whether to lay out items in a row instead of a column.

itemsclass-attributeinstance-attribute​

items: list[Radio] = field(default_factory=list)

The options of this group.

labelclass-attributeinstance-attribute​

label: StrOrControl | None = None

The label shown above this group.

It turns red while error_text is set.

spacingclass-attributeinstance-attribute​

spacing: Number | None = None

The space between items.

If None, defaults to 4.

valueclass-attributeinstance-attribute​

value: str | None = None

The value of the selected option.

If None, no option is selected.

Events​

on_changeclass-attributeinstance-attribute​

on_change: ControlEventHandler[RadioGroup] | None = None

Called when the selected option changes.

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