Button

The button is a clickable node that fires a callback method when pressed or clicked.

../../_images/Button.jpeg

Usage

The most basic button has a text label and a callback method for when it is pressed. The callback expects 1 argument, the instance of the button firing the event.

import toga

def my_callback(button):
    # handle event
    pass

button = toga.Button('Click me', on_press=my_callback)

Supported Platforms

orphan:
Component iOS win32 web django cocoa gtk android
Button yes yes no yes yes yes yes

Reference

class toga.interface.widgets.button.Button(label, id=None, style=None, on_press=None, enabled=None, background_color=None)

Button widget, a clickable button

Parameters:
  • label (str) – Text to be shown on the button
  • 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.
  • on_press (callable) – Function to execute when pressed
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
background_color

Indicates the button background color. :returns: Button background color. Default is None. :rtype: str` or ``tuple

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
enabled

Indicates whether the button can be pressed by the user.

Returns:Button status. Default is True.
Return type:Bool
hide()

Hide the widget from the super view.

id

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

Return type:str
label
Returns:The label value
Return type:str
on_press

The callable function for when the button is pressed

Return type:callable
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