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

Detecting multitapping


The multitapping detection is a useful tool in the development of an app. When more than a touch occurs in a zone, it is what we call a multitap.

Getting ready

We will work with the on_touch_down method, so it could be useful to go through the recipe Evolving to the touchscreen in this chapter. Also, this recipe will use the common button and label widgets for reference.

How to do it…

Follow these steps in this recipe:

  1. First, in the KV file, define a button and an 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. Change the text in the label when a double tap is present.

  4. Change the text in the label when a triple tap is present:

    import kivy
    kivy.require('1.9.0') 
    
    from kivy.app import App
    from kivy.uix.widget import Widget
    
    class MyW(Widget):
    
        def on_touch_down(self...