Option Container#

Availability (Key)#

macOS

GTK

Windows

iOS

Android

Web

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.

Create a base Toga widget.

This is an abstract base class; it cannot be instantiated.

Parameters:
  • id – The ID for the widget.

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

exception OptionException#
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 content#

The sub layouts of the OptionContainer.

Returns:

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

Raises:

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

property current_tab#
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.

refresh_sublayouts()#

Refresh the layout and appearance of this widget.

remove(index)#

Remove the provided widgets as children of this node.

Any nominated child widget that is not a child of this widget will not have any change in parentage.

Raises ValueError if this widget cannot have children.

Parameters:

children – The child nodes to remove.

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.