The use of graphics opens up a diversity of options: one of them is animations. Kivy is useful for this task. For this recipe, we will develop a simple animation of a button where, if you touch it, the animation is performed.
Animations are a natural extension of the graphics concepts. It is good to have those concepts clear so, as recommended, you should read the previous recipes of this chapter.
Here we are going to use KV file where we set the button to perform the animation that will be defined in the Python file as a method of the root widget class. For this, follow these steps:
In the KV file, define the rule for the root widget.
Add a button to the root widget.
Call the
root.animate()
method in theon_press
property of the button:<MyW>: Button: id: button1 text: 'Hello' on_press: root.animate(button1)
In the Python file, import the usual Kivy packages.
Also import the
Animation
package.Define the root widget...