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

Attaching callbacks


Now, we have created a new kind of event, so it is possible to attach callback methods to our new event as we have in the predefined events. For this recipe, we will create a new event and attach a callback function to it. If the button text changes, the event as in the past recipe will be fired.

Getting ready

We will use the code from the previous recipe as the base of this recipe and will add a different touch so that we can change the button when it is double tapped. Hence, I would advise you to go through the previous recipe again. Also, the reader may find the section on multitouching from Chapter 2, Input, Motion, and Touch useful specifically.

How to do it…

Perform the following steps:

  1. First, in the KV file, declare an empty label and a button:

    <MyW>:
        Button:
            id: button1
            text: 'Hello'
        Label:	
            id: label1
            pos: 200,200
            text: ''
  2. In the Python code, define the callback method.

  3. Define the widget class.

  4. In the widget class...