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 →


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,)When to use
Section titled “When to use”- 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 pzfrom 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,)Variants
Section titled “Variants”Content
Section titled “Content”

Code
ui.card(ui.muted("A bordered surface."), width=260)

title=Code
ui.card(ui.muted("Three files changed."), title="Changes", width=260)

title=, actions=Code
ui.card(ui.muted("Three files changed."), title="Changes", actions=[ui.icon_button("ellipsis", on_menu, size="sm")], width=260)Padding
Section titled “Padding”

padding=8Code
ui.card(ui.label("Compact"), padding=8)

padding=16Code
ui.card(ui.label("Default"))

padding=28Code
ui.card(ui.label("Roomy"), padding=28)States and events
Section titled “States and events”

selected=TrueCode
ui.card(ui.muted("Python app with a window"), title="Desktop app", on_press=on_press, selected=True, width=260)

footer=, elevated=TrueCode
ui.card(ui.muted("3 files changed"), title="Commit", footer=[ui.button("Push", on_press)], elevated=True, width=260)Events
Section titled “Events”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().
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 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)from dataclasses import dataclass
@dataclassclass Choose: plan: str
class Plans(pz.App): plan = "Pro"
def update(self, message): match message: case Choose(plan): self.plan = plan
def view(self): return pz.row([ui.card(ui.muted(name), title=name, width=160, selected=name == self.plan, on_press=Choose(name)) for name in ("Free", "Pro", "Team")], spacing=8)from dataclasses import dataclass
@dataclass(frozen=True)class State: plan: str = "Pro"
def plan_card(name, selected, choose): # a small function component return ui.card(ui.muted(name), title=name, width=160, selected=selected, on_press=choose)
def view(state, set_state): return pz.row([plan_card(n, n == state.plan, lambda n=n: set_state(plan=n)) for n in ("Free", "Pro", "Team")], spacing=8)Properties and API
Section titled “Properties and API”ui.card
Section titled “ui.card”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).