This kivy tutorial will show you how to create a simple drawing application using something in kivy called a canvas.
Before we can start drawing anything on the screen we need to import some things from kivy.graphics.
The first thing we will do is simply draw a rectangle to the screen to ensure everything is working. To do this we will create an __init__ method in the class we used in the previous tutorial. In this method we will simply create a rectangle.
Now when we run the program we should see a small rectangle showing up in the corner of our window.
Whenever we want to change the color of something being drawn on the screen we need to redefine the drawing color of the canvas like so.
Now our rectangle will be red.
Here is an example of drawing multiple shapes that are different colors.
This creates the following display.
Simple Drawing App
Now that we know how to draw shapes onto the screen we will create an app that makes a square follow our mouse or finger.
To do this we can simply modify the position of the rect that we define in the __init__ method.
Now as we click down on the screen the rectangle should follow our mouse or finger.
The last thing I will touch on is how to draw lines.
The first thing we need to do is import Line from kivy.graphics.
Next we will simply define a line and give it some points in the __init__ method.