Flex
Lays children out along one axis like CSS flexbox: justify on the main axis (start, center, end, between, around, evenly), align on the cross axis, gap and wrap. pz.flex_item(child, grow=, basis=) makes a child grow or gives it a base size.
pz.flex · 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.column([ pz.flex([box("A"), box("B"), box("C")], justify="between", width=440), pz.flex([box("fixed"), pz.flex_item(box("grows", w="fill"), grow=1), box("fixed")], gap=8, width=440), pz.flex([box("A"), box("B")], justify="center", gap=8, width=440),], spacing=14)When to use
Section titled “When to use”- When
row/columnare not enough: even distribution, growing items, wrapping cards.
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.column([ pz.flex([box("A"), box("B"), box("C")], justify="between", width=440), pz.flex([box("fixed"), pz.flex_item(box("grows", w="fill"), grow=1), box("fixed")], gap=8, width=440), pz.flex([box("A"), box("B")], justify="center", gap=8, width=440),], spacing=14)Variants
Section titled “Variants”Justify
Section titled “Justify”

justify="start"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.flex([box("A"), box("B")], justify="start", gap=8, width=360)

justify="center"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.flex([box("A"), box("B")], justify="center", gap=8, width=360)

justify="end"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.flex([box("A"), box("B")], justify="end", gap=8, width=360)

justify="between"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.flex([box("A"), box("B"), box("C")], justify="between", width=360)

justify="around"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.flex([box("A"), box("B"), box("C")], justify="around", width=360)

justify="evenly"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.flex([box("A"), box("B"), box("C")], justify="evenly", width=360)

flex_item(grow=1)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.flex([box("fixed"), pz.flex_item(box("grows", w="fill"), grow=1), box("fixed")], gap=8, width=360)

wrap=TrueCode
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.flex([box(str(i)) for i in range(1, 7)], gap=8, wrap=True, width=300)Events
Section titled “Events”Flex 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.flex
Section titled “pz.flex”flex( children=(), *, direction='row', justify='start', align='start', gap=0, wrap=False, padding=None, width=None, height=None,)Lays children out along one axis, like CSS flexbox, with justify on the main axis and align on the cross axis. Use pz.flex_item to make a child grow or give it a fixed size.
| Property | Default | Description |
|---|---|---|
children |
() |
The widgets, or pz.flex_item(...) for children with their own sizing. |
direction |
"row" |
"row" or "column". |
justify |
"start" |
"start", "center", "end", "between", "around" or "evenly". No effect when a child grows. |
align |
"start" |
Cross-axis alignment: "start", "center" or "end". |
gap |
0 |
Space between children. |
wrap |
False |
Wraps onto new lines (rows with justify="start" only). |
padding |
None |
Space around the children. |
width |
None |
Width. |
height |
None |
Height. |
pz.flex_item
Section titled “pz.flex_item”flex_item(content, *, grow=1, basis=None, align=None)Sizes a child of pz.flex.
| Property | Default | Description |
|---|---|---|
content |
required | The widget. |
grow |
1 |
Share of the free space on the main axis (0 keeps its natural size). |
basis |
None |
A fixed main size in pixels, instead of growing. |
align |
None |
Cross-axis alignment for this child. |