Skip to content

Scrollable

Makes its content scrollable vertically, horizontally or "both". Give it an id to scroll from code (pz.Command.scroll_to), anchor_bottom=True to stick to the end (chats, logs), and style the rail and scroller with the theme or your own colors.

pz.scrollable · Category: Layout · Full reference →

ScrollableScrollable
  • For long lists, documents and any content taller than its space.
import pyzed as pz
from pyzed import ui
pz.container(pz.scrollable(
pz.column([ui.list_item(f"Item {i}", on_open, icon="file", inset=True) for i in range(1, 30)]),
height=220,
), width=300)
Scrollable: VerticalScrollable: Vertical
Vertical
Code
pz.container(pz.scrollable(pz.column([ui.list_item(f"Item {i}", icon="file", inset=True)
for i in range(1, 30)]), height=130), width=240)
Scrollable: direction="horizontal"Scrollable: direction="horizontal"
direction="horizontal"
Code
pz.container(pz.scrollable(pz.container(pz.row([ui.chip(f"tag {i}") for i in range(1, 25)], spacing=6),
padding=(0, 0, 14, 0)),
direction="horizontal"), width=300)

Scrollable 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_scroll (info) Callable that receives a dict with x, y, relative_x, relative_y, width, height, content_width and content_height.

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 Feed(pz.App):
def __init__(self):
self.items = [f"Post {i}" for i in range(1, 30)]
self.at_end = False
def scrolled(self, info): # on_scroll: x, y, relative_x, relative_y, sizes
self.at_end = info["relative_y"] > 0.95
def view(self):
return pz.column([
pz.scrollable(pz.column([ui.list_item(p, icon="file") for p in self.items]),
height=200, on_scroll=self.scrolled),
ui.muted("You reached the end" if self.at_end else "Scroll down"),
], spacing=6, width=300)
scrollable(
content,
*,
direction='vertical',
width=None,
height=None,
padding=None,
id=None,
anchor_bottom=False,
rail=None,
scroller=None,
scroller_hover=None,
scrollbar_width=8.0,
scroller_width=None,
margin=0.0,
on_scroll=None,
)

Makes its content scrollable.

Property Default Description
content required Content: a Widget, a string or a number (converted to text).
direction "vertical" "vertical", "horizontal" or "both".
width None Width: pixels, "fill", "shrink" or "fill:N" (proportion).
height None Height: pixels, "fill", "shrink" or "fill:N" (proportion).
padding None Inner padding: 8, (vertical, horizontal) or (top, right, bottom, left).
id None Stable identifier used to focus or scroll it with a Command.
anchor_bottom False Keeps the scroll pinned to the end (logs, terminals, chats).
rail None Scrollbar rail color.
scroller None Scroller color.
scroller_hover None Scroller color on hover.
scrollbar_width 8.0 Scrollbar width.
scroller_width None Scroller width (defaults to the scrollbar’s).
margin 0.0 Margin between the scrollbar and the content.

Events: on_scroll (events).

Full reference →