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

Grabbing touch events


There are some moments or areas where we do not want the touch performed in the same way. Therefore, we can grab some inputs to give them special treatment.

Getting ready

We will continue working with the touch profile, so it could be useful to review the previous recipes for a deeper understanding, also we will use the same KV file with the common button and label widgets whereby you will find a detailed explanation of the KV file in the recipe Recognizing touch shapes.

How to do it…

This recipe following the next steps:

  1. In the KV file, define a button and a empty label:

    <MyW>:
        Button:
            id: button1
            pos: 0,0
            text: 'Hello'
    
        Label:
            id: label1
            pos: 200, 200
            text: ''
  2. In the class of the widget in the Python code, we need to override the method on_touch_down.

  3. If the touch coincides with the button area, grab the touch.

  4. In the class of the widget in the Python code, we also need to override the method on_touch_up.

  5. If the...