Widget

The widget class is a base class for all widgets and not designed to be instantiated directly.

Reference

class toga.interface.widgets.base.Widget(id=None, style=None, **config)

This is the base widget implementation that all widgets in Toga derive from.

It defines the interface for core functionality for children, styling, layout and ownership by specific App and Window.

Apart from the above, this is an abstract implementation which must be made concrete by some platform-specific code for the _apply_layout method.

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