Button
Displays a themed button. It reads its colors from the current theme, can carry an icon and a keyboard shortcut, and comes in several variants and sizes. Any style parameter of pz.button (bg, hover_bg, color, shadow, radius…) overrides the theme’s.
ui.button · Category: Actions · Full reference →


pz.row([ ui.button("Cancel", on_cancel, variant="ghost"), ui.button("Save", on_save, icon="save", variant="solid", keys="ctrl-s"),], spacing=8)When to use
Section titled “When to use”- For the main actions of a form, dialog or toolbar.
- Use
variant="solid"for the one primary action and"ghost"for secondary ones. - For a button with only an icon, use Icon button.
import pyzed as pzfrom pyzed import ui
class Editor(pz.App): def save(self): ...
def view(self): return ui.button("Save", self.save, icon="save", keys="ctrl-s")Variants
Section titled “Variants”Variant
Section titled “Variant”filled is the default; use solid for the one main action of a screen.


variant="filled"Code
ui.button("Filled", on_press)

variant="ghost"Code
ui.button("Ghost", on_press, variant="ghost")

variant="subtle"Code
ui.button("Subtle", on_press, variant="subtle")

variant="outline"Code
ui.button("Outline", on_press, variant="outline")

variant="solid"Code
ui.button("Solid", on_press, variant="solid")

variant="tinted"Code
ui.button("Tinted", on_press, variant="tinted")Semantic colors
Section titled “Semantic colors”A color name as variant gives a tinted button; tint= colors a solid one.


variant="accent"Code
ui.button("Upgrade", on_press, variant="accent", icon="sparkles")

variant="success"Code
ui.button("Done", on_press, variant="success", icon="check")

variant="warning"Code
ui.button("Careful", on_press, variant="warning", icon="triangle-alert")

variant="error"Code
ui.button("Delete", on_press, variant="error", icon="trash-2")

variant="info"Code
ui.button("Details", on_press, variant="info", icon="info")

variant="solid", tint="error"Code
ui.button("Delete forever", on_press, variant="solid", tint="error")

size="xs"Code
ui.button("Extra small", on_press, size="xs")

size="sm"Code
ui.button("Small", on_press, size="sm")

size="md"Code
ui.button("Medium", on_press, size="md")

size="lg"Code
ui.button("Large", on_press, size="lg")Content
Section titled “Content”

icon="save"Code
ui.button("Save", on_press, icon="save")

icon_position="end"Code
ui.button("Next", on_press, icon="arrow-right", icon_position="end")

keys="ctrl-s"Code
ui.button("Save", on_press, icon="save", keys="ctrl-s")

icon_color="success"Code
ui.button("Online", on_press, icon="circle", icon_color="success")

Code
ui.button(icon="plus", on_press=on_press)A button without on_press is drawn disabled, so unfinished actions look unfinished.


selected=TrueCode
ui.button("Selected", on_press, selected=True)

disabled=TrueCode
ui.button("Disabled", on_press, disabled=True)

Code
ui.button("Not wired yet")

full_width=TrueCode
pz.container(ui.button("Sign in", on_press, variant="solid", full_width=True), width=280)Style overrides
Section titled “Style overrides”The style arguments of pz.button (bg, hover_bg, pressed_bg, color, border_color, shadow, radius, padding) replace the theme’s values for that button only.


shadow=Code
ui.button("Lifted", on_press, variant="solid", shadow=("#00000066", (0, 4), 12))

bg=, color=Code
ui.button("Custom", on_press, bg="#c678dd", hover_bg="#d08ae6", color="#ffffff")

border_color=Code
ui.button("Gold border", on_press, variant="outline", border_color="#e5c07b")

radius=999Code
ui.button("Pill", on_press, variant="solid", radius=999)States and events
Section titled “States and events”

loading=TrueCode
ui.button("Saving", on_press, icon="save", loading=True)

tooltip=Code
ui.button("Save", on_press, tooltip="Writes the file")Base widget
Section titled “Base widget”The pz.* widget underneath: no theme, every color and size is yours.


pz.buttonCode
pz.button("pz.button", on_press, padding=(6, 14), bg="#3a7bc8", color="#ffffff", radius=6)

Code
pz.button(pz.row([pz.icon("heart", size=14), pz.text("Like")], spacing=6, align="center"), on_press, padding=(6, 12), bg="#c678dd22", color="#c678dd", border_color="#c678dd", border_width=1, radius=999)Examples
Section titled “Examples”Full width
Section titled “Full width”full_width=True stretches the button to its container.


pz.column([ ui.button("Sign in", on_press, variant="solid", full_width=True), ui.button("Create an account", on_press, variant="outline", full_width=True),], spacing=8, width=320)Events
Section titled “Events”Button 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_press |
ui.button, pz.button |
() |
Message or callable sent on press. None disables the control. |
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 Editor(pz.App): def __init__(self): self.saved = 0
def save(self): # on_press: called with nothing self.saved += 1
def view(self): return pz.row([ ui.button("Save", self.save, icon="save", variant="solid", keys="ctrl-s"), ui.button("Reset", lambda: setattr(self, "saved", 0), variant="ghost"), ui.label(f"Saved {self.saved} times"), ], spacing=8, align="center")class Editor(pz.App): saved = 0
def update(self, message): # every button sends a message here match message: case "save": self.saved += 1 case "reset": self.saved = 0
def view(self): return pz.row([ ui.button("Save", "save", icon="save", variant="solid", keys="ctrl-s"), ui.button("Reset", "reset", variant="ghost"), ui.label(f"Saved {self.saved} times"), ], spacing=8, align="center")from dataclasses import dataclass
@dataclass(frozen=True)class State: saved: int = 0
def view(state, set_state): # a pure function: state in, widgets out return pz.row([ ui.button("Save", lambda: set_state(saved=state.saved + 1), icon="save", variant="solid"), ui.button("Reset", lambda: set_state(saved=0), variant="ghost"), ui.label(f"Saved {state.saved} times"), ], spacing=8, align="center")Properties and API
Section titled “Properties and API”ui.button
Section titled “ui.button”button( content=None, on_press=None, *, icon=None, icon_position='start', icon_color=None, variant='filled', tint=None, size='md', selected=False, disabled=False, full_width=False, keys=None, loading=False, tooltip=None, theme=None, **style,)A themed button with variants, sizes, an icon and a shortcut.
| Property | Default | Description |
|---|---|---|
content |
None |
Text or widget. |
icon |
None |
Name of a Lucide icon (pyzed icons lists them). |
icon_position |
"start" |
"start" or "end". |
icon_color |
None |
Icon color: a theme token or a hex color. |
variant |
"filled" |
"filled", "ghost", "subtle", "outline", "solid", "tinted", or a semantic color: "accent", "error", "warning", "success", "info". |
tint |
None |
Color for the solid and tinted variants. |
size |
"md" |
"xs", "sm", "md" or "lg". |
selected |
False |
Marks it as selected. |
disabled |
False |
Disables it (ignores clicks). |
full_width |
False |
Fills the full width. |
keys |
None |
Shortcut shown at the end, written as a string: "ctrl-s", "cmd-k cmd-s". |
loading |
False |
Shows a spinner in place of the icon and ignores presses (keep a pz.every(1/30, ...) subscription while it spins). |
tooltip |
None |
Text shown on hover. |
theme |
None |
Theme to use instead of the current one (pyzed.theme.current()). |
**style |
— | Any pyzed.button style parameter (bg, hover_bg, color…). |
Events: on_press (events).
pz.button
Section titled “pz.button”button( content, on_press=None, *, padding=None, width=None, height=None, bg=None, color=None, border_color=None, border_width=0.0, radius=None, shadow=None, hover_bg=None, hover_color=None, hover_border_color=None, pressed_bg=None, disabled_color=None, clip=False,)A button with no predefined style. For the themed button use ui.button.
| Property | Default | Description |
|---|---|---|
content |
required | Button content. |
padding |
None |
Inner padding: 8, (vertical, horizontal) or (top, right, bottom, left). |
width |
None |
Width: pixels, "fill", "shrink" or "fill:N" (proportion). |
height |
None |
Height: pixels, "fill", "shrink" or "fill:N" (proportion). |
bg |
None |
Background color ("#rrggbb[aa]", (r, g, b[, a]) or "transparent"). |
color |
None |
Text or icon color. |
border_color |
None |
Border color. |
border_width |
0.0 |
Border width in pixels. |
radius |
None |
Corner radius: a number or (top_left, top_right, bottom_right, bottom_left). |
shadow |
None |
Shadow: (color, (dx, dy), blur). |
hover_bg |
None |
Background on hover. |
hover_color |
None |
Text color on hover. |
hover_border_color |
None |
Border color on hover. |
pressed_bg |
None |
Background while pressed. |
disabled_color |
None |
Text color when disabled. |
clip |
False |
Clips content that overflows the bounds. |
Events: on_press (events).