Book Image

Kivy Cookbook

By : Hugo Solis
Book Image

Kivy Cookbook

By: Hugo Solis

Overview of this book

Table of Contents (16 chapters)
Kivy Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Introducing animations


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.

Getting ready

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.

How to do it…

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:

  1. In the KV file, define the rule for the root widget.

  2. Add a button to the root widget.

  3. Call the root.animate() method in the on_press property of the button:

    <MyW>:
        Button:
            id: button1
            text: 'Hello'
            on_press: root.animate(button1)
  4. In the Python file, import the usual Kivy packages.

  5. Also import the Animation package.

  6. Define the root widget...