Skip to content

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 →

ButtonButton
Hover and press states with a real pointer.
  • 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 pz
from pyzed import ui
class Editor(pz.App):
def save(self):
...
def view(self):
return ui.button("Save", self.save, icon="save", keys="ctrl-s")

filled is the default; use solid for the one main action of a screen.

Button: variant="filled"Button: variant="filled"
variant="filled"
Code
ui.button("Filled", on_press)
Button: variant="ghost"Button: variant="ghost"
variant="ghost"
Code
ui.button("Ghost", on_press, variant="ghost")
Button: variant="subtle"Button: variant="subtle"
variant="subtle"
Code
ui.button("Subtle", on_press, variant="subtle")
Button: variant="outline"Button: variant="outline"
variant="outline"
Code
ui.button("Outline", on_press, variant="outline")
Button: variant="solid"Button: variant="solid"
variant="solid"
Code
ui.button("Solid", on_press, variant="solid")
Button: variant="tinted"Button: variant="tinted"
variant="tinted"
Code
ui.button("Tinted", on_press, variant="tinted")

A color name as variant gives a tinted button; tint= colors a solid one.

Button: variant="accent"Button: variant="accent"
variant="accent"
Code
ui.button("Upgrade", on_press, variant="accent", icon="sparkles")
Button: variant="success"Button: variant="success"
variant="success"
Code
ui.button("Done", on_press, variant="success", icon="check")
Button: variant="warning"Button: variant="warning"
variant="warning"
Code
ui.button("Careful", on_press, variant="warning", icon="triangle-alert")
Button: variant="error"Button: variant="error"
variant="error"
Code
ui.button("Delete", on_press, variant="error", icon="trash-2")
Button: variant="info"Button: variant="info"
variant="info"
Code
ui.button("Details", on_press, variant="info", icon="info")
Button: variant="solid", tint="error"Button: variant="solid", tint="error"
variant="solid", tint="error"
Code
ui.button("Delete forever", on_press, variant="solid", tint="error")
Button: size="xs"Button: size="xs"
size="xs"
Code
ui.button("Extra small", on_press, size="xs")
Button: size="sm"Button: size="sm"
size="sm"
Code
ui.button("Small", on_press, size="sm")
Button: size="md"Button: size="md"
size="md"
Code
ui.button("Medium", on_press, size="md")
Button: size="lg"Button: size="lg"
size="lg"
Code
ui.button("Large", on_press, size="lg")
Button: icon="save"Button: icon="save"
icon="save"
Code
ui.button("Save", on_press, icon="save")
Button: icon_position="end"Button: icon_position="end"
icon_position="end"
Code
ui.button("Next", on_press, icon="arrow-right", icon_position="end")
Button: keys="ctrl-s"Button: keys="ctrl-s"
keys="ctrl-s"
Code
ui.button("Save", on_press, icon="save", keys="ctrl-s")
Button: icon_color="success"Button: icon_color="success"
icon_color="success"
Code
ui.button("Online", on_press, icon="circle", icon_color="success")
Button: Icon onlyButton: Icon only
Icon only
Code
ui.button(icon="plus", on_press=on_press)

A button without on_press is drawn disabled, so unfinished actions look unfinished.

Button: selected=TrueButton: selected=True
selected=True
Code
ui.button("Selected", on_press, selected=True)
Button: disabled=TrueButton: disabled=True
disabled=True
Code
ui.button("Disabled", on_press, disabled=True)
Button: No on_pressButton: No on_press
No on_press
Code
ui.button("Not wired yet")
Button: full_width=TrueButton: full_width=True
full_width=True
Code
pz.container(ui.button("Sign in", on_press, variant="solid", full_width=True), width=280)

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.

Button: shadow=Button: shadow=
shadow=
Code
ui.button("Lifted", on_press, variant="solid", shadow=("#00000066", (0, 4), 12))
Button: bg=, color=Button: bg=, color=
bg=, color=
Code
ui.button("Custom", on_press, bg="#c678dd", hover_bg="#d08ae6", color="#ffffff")
Button: border_color=Button: border_color=
border_color=
Code
ui.button("Gold border", on_press, variant="outline", border_color="#e5c07b")
Button: radius=999Button: radius=999
radius=999
Code
ui.button("Pill", on_press, variant="solid", radius=999)
Button: loading=TrueButton: loading=True
loading=True
Code
ui.button("Saving", on_press, icon="save", loading=True)
Button: tooltip=Button: tooltip=
tooltip=
Code
ui.button("Save", on_press, tooltip="Writes the file")

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

Button: pz.buttonButton: pz.button
pz.button
Code
pz.button("pz.button", on_press, padding=(6, 14), bg="#3a7bc8", color="#ffffff", radius=6)
Button: Any contentButton: Any content
Any content
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)

full_width=True stretches the button to its container.

Button: Full widthButton: Full width

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

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

Full reference →

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

Full reference →