Skip to content

Badge

A small pill with text and an optional icon. tint picks a semantic color and variant is "soft" (default), "solid" or "outline".

ui.badge · Category: Display · Full reference →

BadgeBadge
  • For short read-only statuses: beta, M (modified), v0.4, 3 errors.
  • For a round number on top of an icon use Count badge.
import pyzed as pz
from pyzed import ui
pz.row([
ui.badge("accent"),
ui.badge("success", tint="success"),
ui.badge("warning", tint="warning"),
ui.badge("error", tint="error", icon="circle-x"),
], spacing=8)
Badge: tint="accent"Badge: tint="accent"
tint="accent"
Code
ui.badge("accent")
Badge: tint="success"Badge: tint="success"
tint="success"
Code
ui.badge("passed", tint="success")
Badge: tint="warning"Badge: tint="warning"
tint="warning"
Code
ui.badge("pending", tint="warning")
Badge: tint="error"Badge: tint="error"
tint="error"
Code
ui.badge("failed", tint="error")
Badge: tint="info"Badge: tint="info"
tint="info"
Code
ui.badge("info", tint="info")
Badge: tint="#c678dd"Badge: tint="#c678dd"
tint="#c678dd"
Code
ui.badge("custom", tint="#c678dd")
Badge: variant="soft"Badge: variant="soft"
variant="soft"
Code
ui.badge("soft")
Badge: variant="solid"Badge: variant="solid"
variant="solid"
Code
ui.badge("solid", variant="solid")
Badge: variant="outline"Badge: variant="outline"
variant="outline"
Code
ui.badge("outline", variant="outline")
Badge: icon="sparkles"Badge: icon="sparkles"
icon="sparkles"
Code
ui.badge("new", icon="sparkles")
Badge: icon="circle-x"Badge: icon="circle-x"
icon="circle-x"
Code
ui.badge("3 errors", tint="error", icon="circle-x")
Badge: variant="solid", icon=Badge: variant="solid", icon=
variant="solid", icon=
Code
ui.badge("verified", tint="success", variant="solid", icon="check")
Badge: size="sm"Badge: size="sm"
size="sm"
Code
ui.badge("beta", size="sm")
Badge: size="lg"Badge: size="lg"
size="lg"
Code
ui.badge("Pro", size="lg", icon="star")
Badge: on_press=Badge: on_press=
on_press=
Code
ui.badge("3 issues", tint="warning", on_press=on_press)

Badge 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 it 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 Inbox(pz.App):
def __init__(self):
self.unread = 3
def view(self):
return ui.badge(f"{self.unread} new", tint="accent",
on_press=lambda: setattr(self, "unread", 0)) # on_press makes it clickable
badge(
content,
*,
tint='accent',
variant='soft',
icon=None,
size='md',
on_press=None,
theme=None,
)

A small pill for statuses and counters.

Property Default Description
content required Content: a Widget, a string or a number (converted to text).
tint "accent" Semantic color: "accent", "error", "warning", "success", "info" or a token.
variant "soft" "soft", "solid" or "outline".
icon None Name of a Lucide icon (pyzed icons lists them).
size "md" "sm", "md" or "lg".
theme None Theme to use instead of the current one (pyzed.theme.current()).

Events: on_press (events).

Full reference →