Skip to content

Button

Create a clickable button that can be pressed by the user.

Pressing a Button calls a function, specified when the button is created.

Creating a Button

You can create a Button using the following functions:

Button()
Button(text, action, color)
Parameter Type Default Description
text str '' The text shown on the button.
action function None The function to call each time the button is pressed; it receives no parameters.
color Color Color.LIGHT_GRAY The button color.

For example,

button = Button("Play music", playMusic)

where playMusic is a function with zero parameters. This function will be called automatically when the user presses this button.

Once created, you can add it to a Display using the Display's add() function.

Functions

Once a Button has been created, the following functions are available:

Additionally, the following functions are available specially for Buttons:

Function Description
getText() Return the button's text.
setText(text) Set the button's text.
setColor(color) Set the button's color.