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

The differences between the touch and motion events


There is a key difference between touch and motion events. A motion event is a continuous succession of many touch events. However, we also know that a touch event always has the pos profile, namely position information. The motion event, however, is not dispatched throughout the widget tree.

Getting ready

In this recipe, we will use the Kv language for the design of the widgets, so we assume that the reader is familiar with the Kv language or did the lecture of the first chapter. Also, this recipe will use the common button widget for reference.

How to do it…

Use this recipe and follow these steps:

  1. First, in the KV file, define a button:

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

  3. Change the button's position with the information in touch.pos:

    import kivy
    kivy.require('1.9.0') 
    
    from kivy.app import App
    from kivy...