Option Container#

macOS

GTK

Windows

iOS

Android

Web

y

y

y

The Option Container widget is a user-selection control for choosing from a pre-configured list of controls, like a tab view.

../../../_images/OptionContainer.jpeg

Usage#

import toga

container = toga.OptionContainer()

table = toga.Table(['Hello', 'World'])
tree = toga.Tree(['Navigate'])

container.add('Table', table)
container.add('Tree', tree)

Reference#

class toga.widgets.optioncontainer.OptionContainer(id=None, style=None, content=None, on_select=None, factory=None)#

The option container widget.

Parameters:
  • id (str) – An identifier for this widget.

  • style (Style) – an optional style object. If no style is provided then a new one will be created for the widget.

  • content (list of tuple (str, Widget)) – Each tuple in the list is composed of a title for the option and the widget tree that is displayed in the option.

exception OptionException#
args#
with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

add(text=NOT_PROVIDED, widget=NOT_PROVIDED, label=None)#

Add a new option to the option container.

Parameters:
  • text (str) – The text for the option.

  • widget (Widget) – The widget to add to the option.

property app#

The App to which this widget belongs.

When setting the app for a widget, all children of this widget will be recursively assigned to the same app.

Raises ValueError if the widget is already associated with another app.

property can_have_children#

Determine if the node can have children.

This does not resolve whether there actually are any children; it only confirms whether children are theoretically allowed.

property children#

The children of this node. This always returns a list, even if the node is a leaf and cannot have children.

Returns:

A list of the children for this widget.

property content#

The sub layouts of the SplitContainer.

Returns:

A OptionList list of OptionItem. Each element of the list is a sub layout of the SplitContainer

Raises:

ValueError – If the list is less than two elements long.

property current_tab#
property enabled#

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

focus()#

Set this widget to have the current input focus.

property id#

The node identifier. This id can be used to target styling directives.

insert(index, text, widget)#

Insert a new option at the specified index.

Parameters:
  • index (int) – Index for the option.

  • text (str) – The text for the option.

  • widget (Widget) – The widget to add to the option.

property on_select#

The callback function that is invoked when one of the options is selected.

Returns:

(callable) The callback function.

property parent#

The parent of this node.

Returns:

The parent of this node. Returns None if this node is the root node.

refresh()#

Refresh the layout and appearance of the tree this node is contained in.

refresh_sublayouts()#

Refresh the layout and appearance of this widget.

remove(index)#

Remove the provided widgets as children of this node.

This does nothing if a given node is not a child of this node.

Raises ValueError if this node is a leaf, and cannot have children.

Parameters:

children – The child nodes to remove.

property root#

The root of the tree containing this node.

Returns:

The root node. Returns self if this node is the root node.

property tab_index#

The position of the widget in the focus chain for the window.

property window#

The window to which this widget belongs.

When setting the window for a widget, all children of this widget will be recursively assigned to the same window.