Python Kivy How to Draw Shapes

In this Python Kivy article we are going to learn How to Draw Shapes, so particularly we are going to draw Ellipse, Rectangle, Triangle and Line in Python Kivy.

 

 

What is Kivy ?

Kivy is an open source Python framework for developing multi touch applications and user interfaces (UIs) for desktop and mobile platforms. it is designed to be cross platform and can run on different operating systems, including Windows, Linux, macOS, iOS and Android.

Kivy is based on the Model-View-Controller (MVC) architectural pattern and uses declarative approach to define the UI layout and behavior. It provides different built in widgets and graphics primitives, as well as support for multimedia, networking and other advanced features.

Kivy applications are written in Python, which allows for rapid development and easy integration with other Python libraries and tools. Kivy also includes a graphical user interface designer called Kivy Designer, which allows developers to create UIs visually without writing any code.

Kivy is licensed under the MIT license, which allows developers to use it in both open-source and commercial projects. it has large and active community of developers, which contributes to its ongoing development and provides support through online forums, documentation, and tutorials.

 

 

Also if you are interested in Python GUI Development with different libraries, you can check the below links.

 

 

 

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.

 

 

 

 

 

So now run your code and this is the result.

Python Kivy How to Draw Shapes
Python Kivy How to Draw Shapes

 

 

 

 

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 your code and this is the result.

Python Kivy How to Draw Shapes
Python Kivy How to Draw Shapes

 

 

 

 

 

 

Also you can watch the complete video for this article 

 

 

 

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Codeloop
Share via
Copy link
Powered by Social Snap
×