Kivy Tutorials
About Lesson

In this Kivy Tutorial we want to learn about Draw Shapes in Kivy, in this lesson we want to draw different shapes like Rectangle, Circle, Triangle and Line.

 

 

So first of all you need to create a new python file, iam going to call it drawingshapes.py and you need to add this code in that file.

 

In this file we have created a class that extends from RelativeLayout, because we are going to add our shapes in the relative layout. the second class is our main class that extends from App class and we return our MyRelativeLayout class in here.

 

 

After that you need to create another file that is our .kv file, make sure that you give the name as your main window class, for example in the above code my main class name is DrawingWindow, you need to give your kivy file drawingwindow.kv. you can see that we have added our all shapes in our kivy relative layout.

 

 

 

Run the complete code and this is the result.

Kivy Tutorial - Draw Shapes in Kivy
Kivy Tutorial – Draw Shapes in Kivy

 

 

 

Adding Image Shapes to Kivy Window

Also you can add images in your shapes, so for this we are going to create a new python file, iam going to call it imageshapes.py. add this code in your file.

 

 

 

Now create your kivy file, my kivy file name is imageshapewindow.kv, the same as my main class.

 

You can see that we have added a source to our shapes, make sure that you have already added some images in your working directory.

 

 

 

Run the complete code and this is the result

Kivy Tutorial - Draw Shapes in Kivy
Kivy Tutorial – Draw Shapes in Kivy