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

Triggering events


If we want to schedule the events, we can trigger them, which will help you trigger the same event in different parts of your code. In the next described recipe, the event will be triggered when we double tap.

Getting ready

Again, we are going to make use of the double tap, so it is important that you refer to the recipes in Chapter 2, Input, Motion, and Touch. Even though the skeleton of the code is similar to that for the last event, the actions are completely different. Here the unscheduling will be automatic.

How to do it…

Perform the following steps to achieve the goal:

  1. First, in the KV file, declare an empty label using the following code:

    <MyW>:
        Label:
            id: label1
            pos: 200,200
            text: ''
  2. In the Python code, import the Clock object instance.

  3. In the widget class, define the method my_callback().

  4. Also, define the method on_touch_down() where we will define the trigger.

  5. As shown in the following code, using an if statement, select a double tap and...