Skip to content

Icon button

A compact square button that shows a Lucide icon. It is ghost by default, so it fits in toolbars, panel headers and tab bars. tooltip= adds a tooltip on hover.

ui.icon_button · Category: Actions · Full reference →

Icon buttonIcon button
  • For frequent actions whose icon is obvious (search, settings, close, add).
  • Always give it a tooltip when the icon alone may be ambiguous.
  • selected=True shows a toggled state (a panel that is open, a filter that is on).
import pyzed as pz
from pyzed import ui
pz.row([
ui.icon_button("search", on_search, tooltip="Search"),
ui.icon_button("settings", on_settings, tooltip="Settings"),
ui.icon_button("bell", on_notifications, selected=True),
ui.icon_button("plus", on_new, variant="filled"),
], spacing=6)
Icon button: size="xs"Icon button: size="xs"
size="xs"
Code
ui.icon_button("star", on_press, size="xs")
Icon button: size="sm"Icon button: size="sm"
size="sm"
Code
ui.icon_button("star", on_press, size="sm")
Icon button: size="md"Icon button: size="md"
size="md"
Code
ui.icon_button("star", on_press, size="md")
Icon button: size="lg"Icon button: size="lg"
size="lg"
Code
ui.icon_button("star", on_press, size="lg")
Icon button: variant="ghost"Icon button: variant="ghost"
variant="ghost"
Code
ui.icon_button("settings", on_press)
Icon button: variant="filled"Icon button: variant="filled"
variant="filled"
Code
ui.icon_button("settings", on_press, variant="filled")
Icon button: variant="outline"Icon button: variant="outline"
variant="outline"
Code
ui.icon_button("settings", on_press, variant="outline")
Icon button: variant="solid"Icon button: variant="solid"
variant="solid"
Code
ui.icon_button("settings", on_press, variant="solid")
Icon button: variant="tinted"Icon button: variant="tinted"
variant="tinted"
Code
ui.icon_button("settings", on_press, variant="tinted")
Icon button: color="accent"Icon button: color="accent"
color="accent"
Code
ui.icon_button("sparkles", on_press, color="accent")
Icon button: color="success"Icon button: color="success"
color="success"
Code
ui.icon_button("circle-check", on_press, color="success")
Icon button: color="warning"Icon button: color="warning"
color="warning"
Code
ui.icon_button("triangle-alert", on_press, color="warning")
Icon button: color="error"Icon button: color="error"
color="error"
Code
ui.icon_button("trash-2", on_press, color="error", variant="outline")

Drawn as the pointer shows it: tooltips only open on hover.

Icon button: selected=TrueIcon button: selected=True
selected=True
Code
ui.icon_button("panel-left", on_press, selected=True)
Icon button: disabled=TrueIcon button: disabled=True
disabled=True
Code
ui.icon_button("lock", on_press, disabled=True)
Icon button: tooltip="Search"Icon button: tooltip="Search"
tooltip="Search"
Code
ui.icon_button("search", on_press, tooltip="Search")
Icon button: indicator="accent"Icon button: indicator="accent"
indicator="accent"
Code
ui.icon_button("bell", on_press, indicator="accent")
Icon button: tint="error"Icon button: tint="error"
tint="error"
Code
ui.icon_button("trash-2", on_press, tint="error")
Icon button: loading=TrueIcon button: loading=True
loading=True
Code
ui.icon_button("refresh-cw", on_press, loading=True)
Icon button: keys=Icon button: keys=
keys=
Code
ui.icon_button("search", on_press, tooltip="Search", keys="ctrl-f")

Icon 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 Handler gets When
on_press () 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 Toolbar(pz.App):
def __init__(self):
self.bold = False
def toggle_bold(self):
self.bold = not self.bold
def view(self):
return pz.row([
ui.icon_button("bold", self.toggle_bold, selected=self.bold, tooltip="Bold", keys="ctrl-b"),
ui.icon_button("trash-2", self.clear, tooltip="Clear", disabled=not self.bold),
], spacing=4)
def clear(self):
self.bold = False
icon_button(
name,
on_press=None,
*,
size='md',
variant='ghost',
color=None,
selected=False,
disabled=False,
tooltip=None,
keys=None,
tint=None,
loading=False,
indicator=None,
theme=None,
)

A square button with just an icon.

Property Default Description
name required Icon name.
size "md" "xs", "sm", "md" or "lg".
variant "ghost" As in ui.button. Defaults to "ghost".
color None Icon color.
selected False Marks it as selected.
disabled False Disables it (ignores clicks).
tooltip None Tooltip text.
keys None Key binding shown in the tooltip.
tint None Colors it ("error", "accent"…).
loading False Swaps the icon for a spinner and ignores presses.
indicator None Adds a small dot in this color at the top right (unread, changes…).
theme None Theme to use instead of the current one (pyzed.theme.current()).

Events: on_press (events).

Full reference →