Skip to content

List item

A list row: an icon, the text and start/end slots for any widget. It supports selected, focused (focus border), disabled, nesting with indent, and on_right_press for a context menu.

ui.list_item · Category: Lists and menus · Full reference →

List itemList item
  • For any vertical list: recent files, search results, settings categories, people.
  • Use inset=True inside panels so the highlight has a margin.
import pyzed as pz
from pyzed import ui
class Recent(pz.App):
def __init__(self):
self.files = ["main.py", "app.py", "README.md"]
self.current = "main.py"
def view(self):
return pz.column([
ui.list_item(f, lambda f=f: setattr(self, "current", f), icon="file",
selected=f == self.current, inset=True)
for f in self.files
])
List item: TextList item: Text
Text
Code
pz.container(ui.list_item("README.md", on_open), width=240)
List item: icon=List item: icon=
icon=
Code
pz.container(ui.list_item("README.md", on_open, icon="file-text"), width=240)
List item: icon_color=List item: icon_color=
icon_color=
Code
pz.container(ui.list_item("main.py", on_open, icon="file-code", icon_color="#3572a5"), width=240)
List item: end=List item: end=
end=
Code
pz.container(ui.list_item("app.py", on_open, icon="file-code", end=ui.badge("M", tint="warning")), width=240)
List item: start=List item: start=
start=
Code
pz.container(ui.list_item("Buy milk", on_open, start=ui.checkbox(True, on_toggle)), width=240)
List item: color="error"List item: color="error"
color="error"
Code
pz.container(ui.list_item("Delete project", on_open, icon="trash-2", color="error"), width=240)
List item: selected=TrueList item: selected=True
selected=True
Code
pz.container(ui.list_item("main.py", on_open, icon="file-code", selected=True), width=240)
List item: focused=TrueList item: focused=True
focused=True
Code
pz.container(ui.list_item("main.py", on_open, icon="file-code", focused=True), width=240)
List item: disabled=TrueList item: disabled=True
disabled=True
Code
pz.container(ui.list_item("old.txt", on_open, icon="file", disabled=True), width=240)
List item: inset=TrueList item: inset=True
inset=True
Code
pz.container(ui.list_item("main.py", on_open, icon="file-code", selected=True, inset=True), width=240)
List item: indent=24List item: indent=24
indent=24
Code
pz.container(ui.list_item("button.rs", on_open, icon="file-code", indent=24), width=240)

on_right_press opens a context menu and tooltip= shows on hover.

List item: description=List item: description=
description=
Code
pz.container(ui.list_item("main.py", on_press, icon="file", description="src/app"), width=300)
List item: on_double_press=List item: on_double_press=
on_double_press=
Code
pz.container(ui.list_item("Rename me", on_press, icon="pencil", on_double_press=on_rename), width=300)

List item has 3 events 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.
on_right_press () Right click.
on_double_press () Sent on a double click (open, rename…).

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 Recent(pz.App):
def __init__(self):
self.files = ["main.py", "app.py", "README.md"]
self.current = "main.py"
self.opened = None
def view(self):
return pz.column([
ui.list_item(f, lambda f=f: setattr(self, "current", f), icon="file", # on_press
selected=f == self.current, inset=True,
on_double_press=lambda f=f: setattr(self, "opened", f),
on_right_press=lambda f=f: print("menu for", f))
for f in self.files
], width=280)
list_item(
content,
on_press=None,
*,
icon=None,
icon_color=None,
start=None,
end=None,
selected=False,
focused=False,
indent=0,
height=26,
color=None,
inset=False,
disabled=False,
on_right_press=None,
on_double_press=None,
description=None,
tooltip=None,
theme=None,
)

A list row: icon, text and a slot at the end.

Property Default Description
content required Text or widget.
icon None Name of a Lucide icon (pyzed icons lists them).
icon_color None Icon color: a theme token or a hex color.
start None Widgets at the start (left).
end None Widgets at the end (right).
selected False Marks it as selected.
focused False Draws a focus border.
indent 0 Left indentation, in pixels.
height 26 Row height.
color None Text color.
inset False With margin and rounded corners (menus, palettes).
disabled False Disables it (ignores clicks).
description None A muted second line (the row grows to 40 px unless height is set).
tooltip None Text shown on hover.
theme None Theme to use instead of the current one (pyzed.theme.current()).

Events: on_press, on_right_press, on_double_press (events).

Full reference →