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

Creating widgets


Actually, this topic has been almost covered in the last chapters, but now we can give graphics to our widgets. The following recipe will create a widget where the user can create graphics ad lib. When the user performs a touch in the widget, the app will draw a yellow point, and if he maintains the touch and moves it, the app will draw a yellow path for the movement.

Getting ready

We are going to work with the touch directive in this recipe. It is useful to read Differencing between Touch and Motion events recipe in Chapter 2, Input, Motion, and Touch.

How to do it…

We are going to use just one Python file to complete the task where we will define the method of our created widget. Follow these steps of the recipe:

  1. Import the usual Kivy packages.

  2. Define the MyWidget class instanced as a widget.

  3. Define the on_touch_down() callback for the class.

  4. In the method, add canvas, Color, and Ellipse to the widget.

  5. Also add the initial point of the line to be drawn.

  6. Define the on_touch_move...