Defining widget events
Now, we will study the events that are called widget-defined events. These kinds of events are inherent to the widget. This recipe will illustrate it with probably the most common widget—the button. We will perform two events: one when the button is pressed and the other when the button state is changed.
Getting ready
In this recipe, it is necessary to clear the difference between the state of the button and press action. Because the states of the button are not pressed and no pressed, they actually are normal and down. The press action changes between both states of the button.
How to do it…
To accomplish the end goal, follow these steps:
- First in the KV file, declare an empty label using the following code:
<MyW>: Label: id: label1 pos: 200,200 text: ''
- In the Python code, define the widget class.
- In the widget class, define constructor
__init__()
within a button. - Bind the callback methods to the button.
- Define the...