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

Scheduling a one-time event


A one-time event is one of those clock-related events where you perform an event just once after some time has passed.

Getting ready

In this recipe, it is assumed that the reader is acquainted with the Kv language and widgets, especially with labels. Also, we will implement the concept of using a mouse to perform the actions that we learned in Chapter 2, Input, Motion, and Touch, particularly for this recipe, using the mouse to perform the actions.

How to do it…

To complete this recipe, follow these steps:

  1. First, in the KV file, let's declare an empty label. You can do this by using the following code:

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

  3. In the widget class, define the method my_callback(), which will be fired.

  4. Also, override the on_touch_down() method where we will schedule the event, using the following code:

    import kivy
    
    from kivy.app import App
    from kivy.uix.widget...