Segmented
A row of joined buttons where one is selected. on_select receives the chosen option.
ui.segmented · Category: Forms · Full reference →


pz.column([ ui.segmented(["Editor", "Terminal", "Both"], "Editor", on_select), ui.segmented(["Day", "Week", "Month"], "Week", on_select),], spacing=14, align="center")When to use
Section titled “When to use”- To switch between two to five views or modes (Day / Week / Month).
- For icons only, use a Toggle group.
import pyzed as pzfrom pyzed import ui
class Calendar(pz.App): def __init__(self): self.mode = "Week"
def view(self): return ui.segmented(["Day", "Week", "Month"], self.mode, lambda m: setattr(self, "mode", m))Variants
Section titled “Variants”Options
Section titled “Options”

Code
ui.segmented(["Code", "Preview"], "Code", on_select)

Code
ui.segmented(["Day", "Week", "Month"], "Week", on_select)

Code
ui.segmented(["XS", "S", "M", "L", "XL"], "M", on_select)Selection
Section titled “Selection”

Code
ui.segmented(["Editor", "Terminal", "Both"], "Editor", on_select)

Code
ui.segmented(["Editor", "Terminal", "Both"], "Both", on_select)States and events
Section titled “States and events”

Code
ui.segmented([("list", "List", "list"), ("grid", "Grid", "layout-grid")], "grid", on_select)

width="fill"Code
ui.segmented(["Day", "Week", "Month"], "Week", on_select, width=320)

disabled={"Month"}Code
ui.segmented(["Day", "Week", "Month"], "Day", on_select, disabled={"Month"})

size="sm"Code
ui.segmented(["Code", "Preview"], "Code", on_select, size="sm")Events
Section titled “Events”Segmented 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 | Handler gets | When |
|---|---|---|
on_select |
(item) |
Callable that receives the chosen item. |
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 Calendar(pz.App): def __init__(self): self.mode = "Week"
def view(self): return pz.column([ ui.segmented(["Day", "Week", "Month"], self.mode, lambda m: setattr(self, "mode", m)), ui.label(f"Showing a {self.mode.lower()}"), ], spacing=8, align="center")from dataclasses import dataclass
@dataclassclass Mode: name: str
class Calendar(pz.App): mode = "Week"
def update(self, message): match message: case Mode(name): self.mode = name
def view(self): return ui.segmented(["Day", "Week", "Month"], self.mode, Mode)from dataclasses import dataclass
@dataclass(frozen=True)class State: mode: str = "Week"
def view(state, set_state): return ui.segmented(["Day", "Week", "Month"], state.mode, lambda m: set_state(mode=m))Properties and API
Section titled “Properties and API”ui.segmented
Section titled “ui.segmented”segmented( options, selected, on_select=None, *, size='md', width=None, disabled=False, id=None, theme=None,)A group of mutually exclusive buttons.
| Property | Default | Description |
|---|---|---|
options |
required | Strings, (value, label) or (value, label, icon). |
selected |
required | The active value. |
size |
"md" |
"sm", "md" or "lg". |
width |
None |
"fill" stretches the buttons evenly. |
disabled |
False |
True, or the values to disable. |
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).