Skip to content

Kbd

Draws a shortcut written as a string ("ctrl-shift-p", chords like "cmd-k cmd-s") as key caps. On macOS it uses symbols (⌘⇧P) and words elsewhere; pyzed.ui.base.KEY_STYLE forces "symbols" or "words". ui.format_keys returns the labels if you draw them yourself.

ui.kbd · Category: Display · Full reference →

KbdKbd
  • In menus, tooltips, palettes and help screens, to teach shortcuts.
  • Most components already accept keys= and draw it for you (button, menu item, tooltip).
import pyzed as pz
from pyzed import ui
pz.column([
ui.kbd("ctrl-shift-p"),
ui.kbd("ctrl-k ctrl-s"),
pz.row([ui.kbd("escape", size="xs"), ui.kbd("enter", size="xs"), ui.kbd("tab", size="xs")], spacing=8),
], spacing=12, align="center")

Write shortcuts as "ctrl-s"; on macOS ctrl becomes ⌃ and cmd ⌘ automatically.

Kbd: One keyKbd: One key
One key
Code
ui.kbd("enter")
Kbd: CombinationKbd: Combination
Combination
Code
ui.kbd("ctrl-shift-p")
Kbd: ChordKbd: Chord
Chord
Code
ui.kbd("ctrl-k ctrl-s")
Kbd: Special keysKbd: Special keys
Special keys
Code
pz.row([ui.kbd("escape"), ui.kbd("tab"), ui.kbd("backspace"), ui.kbd("up")], spacing=6)
Kbd: size="xs"Kbd: size="xs"
size="xs"
Code
ui.kbd("ctrl-p", size="xs")
Kbd: size="sm"Kbd: size="sm"
size="sm"
Code
ui.kbd("ctrl-p", size="sm")

Kbd has no events of its own: it shows what you give it. 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.

kbd(keys, *, size='sm', theme=None)

Draws a shortcut as keys: "ctrl-shift-p", "cmd-k cmd-s". Uses symbols on macOS (⌘⇧P) and words elsewhere.

Property Default Description
keys required The shortcut.
size "sm" "xs" or "sm".
theme None Theme to use instead of the current one (pyzed.theme.current()).

Full reference →

format_keys(keys)

Splits a shortcut into labels per chord: format_keys("ctrl-shift-p") == [["Ctrl", "Shift", "P"]]. The style is controlled by pyzed.ui.base.KEY_STYLE ("auto", "symbols" or "words").

Property Default Description
keys required The shortcut.

Full reference →

keys_text(keys)

A shortcut as plain text for a label or a status line: keys_text("ctrl-shift-p") == "Ctrl+Shift+P" ("⌃⇧P" with macOS symbols), chords separated by a space. Tooltips, buttons and menus take keys= instead and draw key caps, so never write the keys into their text.

Property Default Description
keys required The shortcut.

Full reference →