Radio group
A set of radio buttons where one option is selected. options are strings or (value, label) pairs; on_select receives the value. horizontal=True lays them out in a row.
ui.radio_group · Category: Forms · Full reference →


pz.row([ ui.radio_group(["Spaces", "Tabs"], "Spaces", on_select), ui.radio_group([("lf", "LF"), ("crlf", "CRLF"), ("cr", "CR")], "lf", on_select, horizontal=True),], spacing=40, align="center")When to use
Section titled “When to use”- When the options need a label each and should all be visible (indentation: spaces or tabs).
- For many options use a Select.
import pyzed as pzfrom pyzed import ui
class Settings(pz.App): def __init__(self): self.indent = "spaces"
def view(self): return ui.radio_group([("spaces", "Spaces"), ("tabs", "Tabs")], self.indent, lambda value: setattr(self, "indent", value))Variants
Section titled “Variants”Direction
Section titled “Direction”

Code
ui.radio_group(["Spaces", "Tabs"], "Spaces", on_select)

horizontal=TrueCode
ui.radio_group(["LF", "CRLF", "CR"], "LF", on_select, horizontal=True)

spacing=16Code
ui.radio_group(["Small", "Medium", "Large"], "Medium", on_select, horizontal=True, spacing=16)Options
Section titled “Options”

Code
ui.radio_group([("lf", "Unix (LF)"), ("crlf", "Windows (CRLF)")], "crlf", on_select)

Code
ui.radio_group(["Yes", "No"], None, on_select, horizontal=True)States and events
Section titled “States and events”

disabled={"CR"}Code
ui.radio_group(["LF", "CRLF", "CR"], "LF", on_select, horizontal=True, disabled={"CR"})

descriptions=Code
ui.radio_group(["Spaces", "Tabs"], "Spaces", on_select, descriptions={"Spaces": "Indent with 4 spaces", "Tabs": "One tab per level"})Base widget
Section titled “Base widget”The pz.* widget underneath: no theme, every color and size is yours.


pz.radioCode
pz.row([pz.radio("Cats", True, on_select, accent="#e5c07b"), pz.radio("Dogs", False, on_select, accent="#e5c07b")], spacing=16)Events
Section titled “Events”Radio group has 1 event of its own, listed below. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.
| Event | Of | Handler gets | When |
|---|---|---|---|
on_select |
ui.radio_group, pz.radio |
(value) |
Callable that receives the chosen value. |
Handler gets is what Pyzed passes to your callable: () means nothing. Any handler can also be a message (a value that is not callable), which goes to update().
Handling the events
Section titled “Handling the events”The same events written three ways. Imperative: methods of the app change self. Declarative: the handlers produce messages and one update() decides. Functional: a pure function draws an immutable state and asks for changes with set_state(...). See Imperative, declarative and functional.
class Settings(pz.App): def __init__(self): self.indent = "spaces"
def set_indent(self, value): # on_select gets the value, not the label self.indent = value
def view(self): return ui.radio_group([("spaces", "Spaces"), ("tabs", "Tabs")], self.indent, self.set_indent)from dataclasses import dataclass
@dataclassclass Indent: value: str
class Settings(pz.App): indent = "spaces"
def update(self, message): match message: case Indent(value): self.indent = value
def view(self): return ui.radio_group([("spaces", "Spaces"), ("tabs", "Tabs")], self.indent, Indent)from dataclasses import dataclass
@dataclass(frozen=True)class State: indent: str = "spaces"
def view(state, set_state): return ui.radio_group([("spaces", "Spaces"), ("tabs", "Tabs")], state.indent, lambda value: set_state(indent=value), horizontal=True)Properties and API
Section titled “Properties and API”ui.radio_group
Section titled “ui.radio_group”radio_group( options, selected, on_select=None, *, horizontal=False, spacing=8, disabled=False, descriptions=None, id=None, theme=None,)Mutually exclusive options as radio buttons.
| Property | Default | Description |
|---|---|---|
options |
required | Strings or (value, label) pairs. |
selected |
required | Current value. |
horizontal |
False |
In a row instead of a column. |
spacing |
8 |
Space between children, in pixels. |
disabled |
False |
True, or the values to disable. |
descriptions |
None |
Maps values to a muted line under their label. |
id |
None |
Stable identifier used to focus or scroll it with a Command. |
theme |
None |
Theme to use instead of the current one (pyzed.theme.current()). |
Events: on_select (events).
pz.radio
Section titled “pz.radio”radio( label, selected, on_select=None, *, size=None, text_size=None, spacing=None, accent=None, bg=None, border_color=None, color=None,)A radio button. Group several yourself (or use ui.radio_group); on_select is sent when it is clicked.
| Property | Default | Description |
|---|---|---|
label |
required | Label text. |
selected |
required | Whether it is checked. |
size |
None |
Size. |
text_size |
None |
Text size. |
spacing |
None |
Space between the circle and the text. |
accent |
None |
Accent color (active part). |
bg |
None |
Background color ("#rrggbb[aa]", (r, g, b[, a]) or "transparent"). |
border_color |
None |
Border color. |
color |
None |
Text or icon color. |
Events: on_select (events).