Responsive
Calls function(width, height) with the space it really gets and shows what it returns, so the layout can adapt: hide a sidebar when the window is narrow, change the number of columns…
pz.responsive · Category: Layout · Full reference →


box = lambda text, w=90, h=44: pz.container(ui.label(text), center=True, width=w, height=h, bg=pz.theme.current().element, radius=6)pz.container(pz.responsive(lambda w, h: pz.center(pz.column([ ui.muted(f"{w:.0f} × {h:.0f} px available"), pz.row([box("1"), box("2"), box("3"), box("4")], spacing=8) if w > 400 else pz.column([box("1"), box("2")], spacing=8),], spacing=10, align="center"))), width=480, height=150)When to use
Section titled “When to use”- For layouts that must work both in a small and a large window.
import pyzed as pzfrom pyzed import ui
box = lambda text, w=90, h=44: pz.container(ui.label(text), center=True, width=w, height=h, bg=pz.theme.current().element, radius=6)pz.container(pz.responsive(lambda w, h: pz.center(pz.column([ ui.muted(f"{w:.0f} × {h:.0f} px available"), pz.row([box("1"), box("2"), box("3"), box("4")], spacing=8) if w > 400 else pz.column([box("1"), box("2")], spacing=8),], spacing=10, align="center"))), width=480, height=150)Variants
Section titled “Variants”Available width
Section titled “Available width”The same code, given two widths: the layout changes by itself.


width=200Code
box = lambda text, w=90, h=44: pz.container(ui.label(text), center=True, width=w, height=h, bg=pz.theme.current().element, radius=6)pz.container(pz.responsive(lambda w, h: pz.row([box("1"), box("2"), box("3")], spacing=8) if w > 300 else pz.column([box("1"), box("2")], spacing=8)), width=200, height=110)

width=400Code
box = lambda text, w=90, h=44: pz.container(ui.label(text), center=True, width=w, height=h, bg=pz.theme.current().element, radius=6)pz.container(pz.responsive(lambda w, h: pz.row([box("1"), box("2"), box("3")], spacing=8) if w > 300 else pz.column([box("1"), box("2")], spacing=8)), width=400, height=60)Events
Section titled “Events”Responsive 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.
Properties and API
Section titled “Properties and API”pz.responsive
Section titled “pz.responsive”responsive(function)Builds its content with function(width, height) using the space actually available, so the layout can adapt (for example, hiding a sidebar when the window is narrow).
| Property | Default | Description |
|---|---|---|
function |
required | Function that receives (width, height) and returns a widget. |