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

Using the gyroscope


Mobile devices today also have a gyroscope. The gyroscope is considered as a no-touch event. This kind of event does not have a start or an end; it is always providing information.

Getting ready

For this recipe, we will use the Kv language for the design of the widgets. Also, this recipe will use the common button and label widgets for reference. Obviously, to run the code of this recipe properly, a device with a gyroscope is necessary.

It is necessary to install a package to use the gyroscope with any mobile device. While there is a way to deal with specific devices, we do not have to reinvent the wheel. Let's use the plyer package, which is an effort from many of the Kivy developers. To install the package from the shell, use:

$ sudo pip plyer install

How to do it…

To complete this recipe, follow these steps:

  1. In the KV file, define the four labels and the button:

    <Acce>:
        Label:
            id: label1
            pos: 150, 300
            text: 'X: '
    
        Label:
            id:...