Skip to content
Toga
0.5.3.dev143+gabcc6cdb6

Box

A generic container for other widgets. Used to construct layouts.

Availability (Key)

macOS GTK Windows iOS Android Web Terminal

Usage

An empty Box can be constructed without any children, with children added to the box after construction:

import toga

box = toga.Box()

label1 = toga.Label('Hello')
label2 = toga.Label('World')

box.add(label1)
box.add(label2)

Alternatively, children can be specified at the time the box is constructed:

import toga

label1 = toga.Label('Hello')
label2 = toga.Label('World')

box = toga.Box(children=[label1, label2])

In most apps, a layout is constructed by building a tree of boxes inside boxes, with concrete widgets (such as Label or Button) forming the leaf nodes of the tree. Style directives can be applied to enforce a margin around the outside of the box, direction of child stacking inside the box, and background color of the box.

Reference

toga.Box

Box(id=None, style=None, children=None, **kwargs)

Bases: Widget

Create a new Box container widget.

PARAMETER DESCRIPTION
id

The ID for the widget.

TYPE: str | None DEFAULT: None

style

A style object. If no style is provided, a default style will be applied to the widget.

TYPE: StyleT | None DEFAULT: None

children

An optional list of children for to add to the Box.

TYPE: Iterable[Widget] | None DEFAULT: None

kwargs

Initial style properties.

DEFAULT: {}

enabled property writable

enabled

Is the widget currently enabled? i.e., can the user interact with the widget?

Box widgets cannot be disabled; this property will always return True; any attempt to modify it will be ignored.

focus

focus()

No-op; Box cannot accept input focus.

toga.Row

Row(*args, **kwargs)

Shorthand for Box with its pack-direction set to "row".

toga.Column

Column(*args, **kwargs)

Shorthand for Box with its pack-direction set to "column".