Skip to content

Segmented

A row of joined buttons where one is selected. on_select receives the chosen option.

ui.segmented · Category: Forms · Full reference →

SegmentedSegmented
  • To switch between two to five views or modes (Day / Week / Month).
  • For icons only, use a Toggle group.
import pyzed as pz
from 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))
Segmented: Two optionsSegmented: Two options
Two options
Code
ui.segmented(["Code", "Preview"], "Code", on_select)
Segmented: Three optionsSegmented: Three options
Three options
Code
ui.segmented(["Day", "Week", "Month"], "Week", on_select)
Segmented: Five optionsSegmented: Five options
Five options
Code
ui.segmented(["XS", "S", "M", "L", "XL"], "M", on_select)
Segmented: FirstSegmented: First
First
Code
ui.segmented(["Editor", "Terminal", "Both"], "Editor", on_select)
Segmented: LastSegmented: Last
Last
Code
ui.segmented(["Editor", "Terminal", "Both"], "Both", on_select)
Segmented: With iconsSegmented: With icons
With icons
Code
ui.segmented([("list", "List", "list"), ("grid", "Grid", "layout-grid")], "grid", on_select)
Segmented: width="fill"Segmented: width="fill"
width="fill"
Code
ui.segmented(["Day", "Week", "Month"], "Week", on_select, width=320)
Segmented: disabled={"Month"}Segmented: disabled={"Month"}
disabled={"Month"}
Code
ui.segmented(["Day", "Week", "Month"], "Day", on_select, disabled={"Month"})
Segmented: size="sm"Segmented: size="sm"
size="sm"
Code
ui.segmented(["Code", "Preview"], "Code", on_select, size="sm")

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

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

Full reference →