-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Kivy Cookbook
By :

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.
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.
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:
Import the usual Kivy packages.
Define the MyWidget
class instanced as a widget.
Define the on_touch_down()
callback for the class.
In the method, add canvas
, Color
, and Ellipse
to the widget.
Also add the initial point of the line to be drawn.
Define the on_touch_move...
Change the font size
Change margin width
Change background colour