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

Evolving to the touchscreen


In this recipe, we are evolving to the touchscreen. Here, you will see the basic differences between the mouse and the touchscreen. This will give us more options than with the mouse device.

Getting ready

For this recipe, we will use the Kv language for the design of the widgets, so make sure that you are confident with it and refresh your knowledge if necessary. Also, this recipe will use the common button and label widgets for reference. Obviously, to get more benefit, a touchscreen device is useful to run the code.

How to do it…

Perform the following steps:

  1. In the KV file, declare the button and the label:

    <MyW>:
        Button:
            id: button1
            text: 'Hello'
        Label:
            id: label1
            pos: 100, 100
            text: 'My label before press the screen'
  2. In the class of the widget in the Python code, we need to override the method on_touch_down

  3. Change the button text with the information in touch.button

  4. Change the label text with the information in...