Skip to content

Card

A rounded, bordered surface that groups content. title and actions add a header row; padding and width control its box.

ui.card · Category: Display · Full reference →

CardCard
  • To group related content on a page: a summary, a form section, a dashboard tile.
  • For a dialog over the UI use Modal.
import pyzed as pz
from pyzed import ui
ui.card(
pz.column([
ui.muted("Pyzed draws the UI with Iced, in Rust."),
pz.row([pz.hspace(), ui.button("Cancel", on_cancel, variant="ghost"),
ui.button("OK", on_ok, variant="solid")], spacing=8),
], spacing=12),
title="Card",
actions=[ui.icon_button("ellipsis", on_menu, size="sm")],
width=380,
)
Card: Content onlyCard: Content only
Content only
Code
ui.card(ui.muted("A bordered surface."), width=260)
Card: title=Card: title=
title=
Code
ui.card(ui.muted("Three files changed."), title="Changes", width=260)
Card: title=, actions=Card: title=, actions=
title=, actions=
Code
ui.card(ui.muted("Three files changed."), title="Changes",
actions=[ui.icon_button("ellipsis", on_menu, size="sm")], width=260)
Card: padding=8Card: padding=8
padding=8
Code
ui.card(ui.label("Compact"), padding=8)
Card: padding=16Card: padding=16
padding=16
Code
ui.card(ui.label("Default"))
Card: padding=28Card: padding=28
padding=28
Code
ui.card(ui.label("Roomy"), padding=28)
Card: selected=TrueCard: selected=True
selected=True
Code
ui.card(ui.muted("Python app with a window"), title="Desktop app", on_press=on_press,
selected=True, width=260)
Card: footer=, elevated=TrueCard: footer=, elevated=True
footer=, elevated=True
Code
ui.card(ui.muted("3 files changed"), title="Commit", footer=[ui.button("Push", on_press)],
elevated=True, width=260)

Card 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 () Makes the whole card clickable.

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 Plans(pz.App):
def __init__(self):
self.plan = "Pro"
def view(self):
return pz.row([
ui.card(ui.muted(f"Plan {name}"), title=name, width=160, selected=name == self.plan,
on_press=lambda name=name: setattr(self, "plan", name)) # the whole card
for name in ("Free", "Pro", "Team")
], spacing=8)
card(
content,
*,
title=None,
actions=(),
padding=16,
width=None,
footer=(),
on_press=None,
selected=False,
elevated=False,
theme=None,
)

A bordered surface to group content, with an optional title and actions.

Property Default Description
content required Content: a Widget, a string or a number (converted to text).
title None Title.
actions () Extra widgets (usually buttons) shown as actions.
padding 16 Inner padding.
width None Width: pixels, "fill", "shrink" or "fill:N" (proportion).
footer () Widgets at the bottom right (buttons).
selected False Outlines it in the accent color.
elevated False Adds a shadow.
theme None Theme to use instead of the current one (pyzed.theme.current()).

Events: on_press (events).

Full reference →