Skip to content

Container

Wraps one child to give it a size, padding and alignment, and to draw a background (color or gradient), a border, rounded corners and a shadow. pz.center(child) is a container that centers its child in all the available space.

pz.container · Category: Layout · Full reference →

ContainerContainer
  • Whenever a widget needs a box: cards, colored areas, fixed sizes, centering.
import pyzed as pz
from pyzed import ui
t = pz.theme.current()
pz.row([
pz.container(ui.label("padding + bg"), padding=16, bg=t.element, radius=8),
pz.container(ui.label("border"), padding=16, border_color=t.accent, border_width=2, radius=8),
pz.container(ui.label("shadow", color="#ffffff"), padding=16, radius=12,
gradient=(135, ["#7c3aed", "#3b82f6"]),
shadow=("#00000066", (0, 6), 18)),
], spacing=16, align="center")
Container: padding=, bg=Container: padding=, bg=
padding=, bg=
Code
pz.container(ui.label("padding + bg"), padding=16, bg=pz.theme.current().element, radius=8)
Container: border_color=, border_width=Container: border_color=, border_width=
border_color=, border_width=
Code
pz.container(ui.label("border"), padding=16, border_color=pz.theme.current().accent,
border_width=2, radius=8)
Container: radius=999Container: radius=999
radius=999
Code
pz.container(ui.label("pill"), padding=(6, 16), bg=pz.theme.current().element, radius=999)
Container: gradient=Container: gradient=
gradient=
Code
pz.container(ui.label("gradient", color="#ffffff"), padding=16, radius=10,
gradient=(135, ["#7c3aed", "#3b82f6"]))
Container: shadow=Container: shadow=
shadow=
Code
pz.container(ui.label("shadow"), padding=16, radius=10, bg=pz.theme.current().elevated,
shadow=("#00000066", (0, 6), 18))
Container: center=TrueContainer: center=True
center=True
Code
pz.container(ui.label("centered"), center=True, width=220, height=90,
border_color=pz.theme.current().border, border_width=1, radius=8)
Container: align_x="end", align_y="end"Container: align_x="end", align_y="end"
align_x="end", align_y="end"
Code
pz.container(ui.label("bottom right"), align_x="end", align_y="end", padding=8,
width=220, height=90, border_color=pz.theme.current().border, border_width=1, radius=8)

pz.center (or center=True) centers the child in the space it gets.

Container: CenteringContainer: Centering

Container 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.

container(
content=None,
*,
padding=None,
width=None,
height=None,
max_width=None,
max_height=None,
align_x=None,
align_y=None,
center=False,
bg=None,
color=None,
border_color=None,
border_width=0.0,
radius=None,
shadow=None,
clip=False,
gradient=None,
)

Wraps a child to give it size, alignment, background, border, radius and shadow.

Property Default Description
content None The child (or None for an empty box, handy as a colored rectangle).
padding None Inner padding: 8, (vertical, horizontal) or (top, right, bottom, left).
width None Width: pixels, "fill", "shrink" or "fill:N" (proportion).
height None Height: pixels, "fill", "shrink" or "fill:N" (proportion).
max_width None Maximum width in pixels.
max_height None Maximum height in pixels.
align_x None Horizontal alignment: "start"/"left", "center", "end"/"right".
align_y None Vertical alignment: "start"/"top", "center", "end"/"bottom".
center False Centers the content on both axes and fills all the space.
bg None Background color ("#rrggbb[aa]", (r, g, b[, a]) or "transparent").
color None Text or icon color.
border_color None Border color.
border_width 0.0 Border width in pixels.
radius None Corner radius: a number or (top_left, top_right, bottom_right, bottom_left).
shadow None Shadow: (color, (dx, dy), blur).
clip False Clips content that overflows the bounds.
gradient None Linear background gradient: (angle, [colors]) or (angle, [(position, color), ...]).

Full reference →

center(content, **kwargs)

Centers content in all the available space. Equivalent to container(content, center=True).

Property Default Description
content required Content: a Widget, a string or a number (converted to text).
**kwargs — Any container parameter.

Full reference →