Skip to content

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 →

Radio groupRadio group
  • 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 pz
from 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))
Radio group: VerticalRadio group: Vertical
Vertical
Code
ui.radio_group(["Spaces", "Tabs"], "Spaces", on_select)
Radio group: horizontal=TrueRadio group: horizontal=True
horizontal=True
Code
ui.radio_group(["LF", "CRLF", "CR"], "LF", on_select, horizontal=True)
Radio group: spacing=16Radio group: spacing=16
spacing=16
Code
ui.radio_group(["Small", "Medium", "Large"], "Medium", on_select, horizontal=True, spacing=16)
Radio group: (value, label) pairsRadio group: (value, label) pairs
(value, label) pairs
Code
ui.radio_group([("lf", "Unix (LF)"), ("crlf", "Windows (CRLF)")], "crlf", on_select)
Radio group: Nothing selectedRadio group: Nothing selected
Nothing selected
Code
ui.radio_group(["Yes", "No"], None, on_select, horizontal=True)
Radio group: disabled={"CR"}Radio group: disabled={"CR"}
disabled={"CR"}
Code
ui.radio_group(["LF", "CRLF", "CR"], "LF", on_select, horizontal=True, disabled={"CR"})
Radio group: descriptions=Radio group: descriptions=
descriptions=
Code
ui.radio_group(["Spaces", "Tabs"], "Spaces", on_select,
descriptions={"Spaces": "Indent with 4 spaces", "Tabs": "One tab per level"})

The pz.* widget underneath: no theme, every color and size is yours.

Radio group: pz.radioRadio group: pz.radio
pz.radio
Code
pz.row([pz.radio("Cats", True, on_select, accent="#e5c07b"),
pz.radio("Dogs", False, on_select, accent="#e5c07b")], spacing=16)

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().

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)
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).

Full reference →

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).

Full reference →