Box¶
The box is a generic container for any widgets, boxes leverage the layout model from the BeeWare Colosseum package.
Usage¶
A box can be instantiated with no children and then the children added later
import toga
box = toga.Box('box1')
button = toga.Button('Hello world', on_press=button_handler)
box.add(button)
To create boxes within boxes, use the children argument.
import toga
box_a = toga.Box('box_a')
box_b = toga.Box('box_b)
box = toga.Box('box', children=[box_a, box_b])
Box Styling¶
Styling of boxes through colosseum can be done pre instantiation or post,
import toga
box = toga.Box('box1')
box.style.set(flex_direction='column', padding_top=10)
import toga
from colosseum import CSS
style = CSS(padding_top=10)
box = toga.Box('box', style=style)
Supported Platforms¶
Component | iOS | win32 | web | django | cocoa | gtk | android |
---|---|---|---|---|---|---|---|
Box |
Reference¶
-
class
toga.interface.widgets.box.
Box
(id=None, style=None, children=None)¶ This is a Widget that contains other widgets, but has no rendering or interaction of its own.
Parameters: - id (
str
) – An identifier for this widget. - style (
colosseum.CSSNode
) – an optional style object. If no style is provided then a new one will be created for the widget. - children (
list
) – An optional list of child Widgets that will be in this box.
-
add
(child)¶ Add a widget as a child of this one.
Raises an
ValueError
if this widget is a leaf, and cannot have children.Parameters: child ( toga.Widget
) – The child to add to the widget
-
app
¶ The App to which this widget belongs.
Return type: toga.App
-
children
¶ The children of this node.
This always returns a list, even if the node is a leaf and cannot have children.
Return type: list
Returns: A list of the children for this widget
-
hide
()¶ Hide the widget from the super view.
-
id
¶ The node identifier. This id can be used to target CSS directives
Return type: str
-
parent
¶ The parent of this node.
Return type: toga.Widget
-
set_font
(font)¶ Set a font on this widget.
Parameters: font ( toga.Font
) – The new font
-
show
()¶ Show the widget on the super view.
-
style
¶ The style object for this widget.
Returns: The style for this widget Return type: colosseum.CSSNode
-
window
¶ The Window to which this widget belongs.
Return type: toga.Window
- id (