Button¶
The button is a clickable node that fires a callback method when pressed or clicked.
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¶
Component | iOS | win32 | web | django | cocoa | gtk | android |
---|---|---|---|---|---|---|---|
Button |
Reference¶
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 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
The App to which this widget belongs.
Return type: toga.App
Indicates the button background color. :returns: Button background color. Default is None. :rtype:
str` or ``tuple
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
Indicates whether the button can be pressed by the user.
Returns: Button status. Default is True. Return type: ``Bool`
Hide the widget from the super view.
The node identifier. This id can be used to target CSS directives
Return type: str
Returns: The label value Return type: str
The callable function for when the button is pressed
Return type: callable
The parent of this node.
Return type: toga.Widget
Set a font on this widget.
Parameters: font ( toga.Font
) – The new font
Show the widget on the super view.
The style object for this widget.
Returns: The style for this widget Return type: colosseum.CSSNode
The Window to which this widget belongs.
Return type: toga.Window
- label (