Skip to content

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 →

ResponsiveResponsive
  • For layouts that must work both in a small and a large window.
import pyzed as pz
from 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)

The same code, given two widths: the layout changes by itself.

Responsive: width=200Responsive: width=200
width=200
Code
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)
Responsive: width=400Responsive: width=400
width=400
Code
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)

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.

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.

Full reference →