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

Modifying with multitouching


A modern use of the gestures and touches is to change the graphics of the app. What things such as pinch to zoom actually do is to scale the canvas of a widget. In this recipe, we will use the scatter widget that Kivy has for these purposes.

Getting ready

The magic of this kind of widget is understood well in the Kivy widgets tree. You could check Chapter 4, Widgets in the recipe Manipulating the widget tree.

How to do it…

You will use a Python file where you will add and set the scatter widget to the root widget. To complete the task, follow these steps:

  1. In the Python file, import the usual packages to work with Kivy.

  2. Import the Scatter widget.

  3. Define a class for the root widget.

  4. Create a simple button with a label.

  5. Create the scatter widget.

  6. Add the button to the scatter widget.

  7. Add the scatter widget to the root widget as follows:

    import kivy
    
    from kivy.app import App
    from kivy.uix.widget import Widget
    from kivy.uix.button import Button
    from kivy.uix.scatter import Scatter...