Button#

A widget that can be pressed or clicked to cause an action in an application.

../../../_images/Button.jpeg

Availability#

macOS

GTK

Windows

iOS

Android

Web

y

y

y

y

y

y

Usage#

A button has a text label. A handler can be associated with button press events.

import toga

def my_callback(button):
    # handle event
    pass

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

Notes#

  • A background color of TRANSPARENT will be treated as a reset of the button to the default system color.

  • On macOS, the button text color cannot be set directly; any color style directive will be ignored. The text color is automatically selected by the platform to contrast with the background color of the button.

Reference#

class toga.widgets.button.Button(text=NOT_PROVIDED, id=None, style=None, on_press=None, enabled=True, factory=None, label=None)#

Create a new button widget.

Inherits from Widget.

Parameters:
  • text – The text to display on the button.

  • id – The ID for the widget.

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

  • on_press – A handler that will be invoked when the button is pressed.

  • enabled – Is the button enabled (i.e., can it be pressed?). Optional; by default, buttons are created in an enabled state.

  • factoryDeprecated

  • labelDeprecated; renamed text.

property label#

The text label displayed on the button.

Deprecated:

label has been renamed text.

property on_press#

The handler to invoke when the button is pressed.

property text#

The text displayed on the button.