Skip to content

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 →

FlexFlex
  • When row/column are not enough: even distribution, growing items, wrapping cards.
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.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)
Flex: justify="start"Flex: justify="start"
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)
Flex: justify="center"Flex: justify="center"
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)
Flex: justify="end"Flex: justify="end"
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)
Flex: justify="between"Flex: justify="between"
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)
Flex: justify="around"Flex: justify="around"
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)
Flex: justify="evenly"Flex: justify="evenly"
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: flex_item(grow=1)Flex: flex_item(grow=1)
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)
Flex: wrap=TrueFlex: wrap=True
wrap=True
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(str(i)) for i in range(1, 7)], gap=8, wrap=True, width=300)

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.

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.

Full reference →

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.

Full reference →