Hello programmers, are you interested in app development using python, then welcome to Python Kivy Tutorial For Beginners. In this tutorial, you will learn what is kivy, where it is used, and how to work with it in python. So let’s gets started.
- 1 Python Kivy Tutorial For Beginners – An Introduction To Kivy
- 2 Python Kivy Tutorial For Beginners – Installing Kivy
- 3 Python Kivy Tutorial For Beginners – Creating First App
- 4 Also Check
Python Kivy Tutorial For Beginners – An Introduction To Kivy
What Is Kivy ?
- Kivy is a graphical user interface Python library that allows you to develop multi platform applications on Windows, MacOS, Android, iOS, Linux, and Raspberry Pi.
- What is better is that it performs better than HTML5 cross platform alternatives.
- It can natively use most inputs, protocols and devices including WM_Touch, WM_Pen, Mac OS X Trackpad and Magic Mouse, Mtdev, Linux Kernel HID, TUIO. A multi-touch mouse simulator is included.
- The best thing of kivy is that this framework is stable and has a well documented API, plus a programming guide to help you get started.
If you want to learn kivy then you must have basic knowledge of following :
- Concepts of OOPS
Python Kivy Tutorial For Beginners – Installing Kivy
To use kivy, we have to download and install it. In this tutorial i am using windows so i will show you how to install kivy on windows. Anyway if you want to install it on any other OS then visit kivy’s official website. By following this site you can easily install it on your machine. So let’s do it on windows OS.
I assume that you have already installed python and pip on your machine. If not then check them first :
1. Update the pip and wheel before installing kivy
Now open your command prompt and run following command.
python -m pip install --upgrade pip wheel setuptools
While executing it looks like following.
2. Installing Dependencies
Now install dependency by executing following commands.
python -m pip install docutils pygments pypiwin32 kivy_deps.sdl2==0.1.22 kivy_deps.glew==0.1.12
- Now run the following command.
python -m pip install kivy_deps.gstreamer==0.1.17
- Now install one other dependency. Run the following command.
python -m pip install kivy_deps.angle==0.1.9
3. Installing kivy
Now install the kivy by executing following command.
4. Installing PyGame
Since PyGame is a dependency of Kivy, we’ll grab that first. PyGame is one of the original packages for creating games in Python. So now run following command.
python -m pip install pygame
So we have installed all dependencies successfully and now it’s time to create our first app in kivy. So let’s gets started.
Python Kivy Tutorial For Beginners – Creating First App
So are you ready to create your app? yes then let’s do it.
The first thing we need to do is to install some modules. So write the following code on your editor(Here i am using Sublime Text 3, you can check this How to run python code on Sublime Text 3 ?).
import kivy # This will give you ability to use all the different fields as well as methods provided by kivy. from kivy.app import App from kivy.uix.label import Label
Creating Class To Represent Our Window
Now we will create a class that will represent our window. So write the following code.
class MyFirstKivyApp(App): def build(self): return Label(text="Welcome To Kivy World !!!")
- MyFirstKivyApp inherits all the fields and methods from Kivy.
- build() returns the content we want to place on the window.
- In the code above, we have returned a label widget with text “Welcome To Kivy World”.
Running Our App
So now to make run our program we need to write the following code.
if __name__ == "__main__": MyFirstKivyApp().run()
Complete Code Of My First App
So here is the complete code for the above code snippets. It looks like as below.
import kivy from kivy.app import App from kivy.uix.label import Label class MyFirstKivyApp(App): def build(self): return Label(text="Welcome To Kivy World !!!") if __name__ == "__main__": MyFirstKivyApp().run()
Now run the above code. Are you excited to see your first kivy application, then what are waiting for? let’s see.
Hey congratulations, we have created our first kivy application successfully. Have you enjoyed it? Let me know in comment section.
So guys this was all about Python Kivy Tutorial For Beginners. I hope you have enjoyed it and learned lots of useful stuffs. If yes then just help your friends by sharing this. And if you have any problem regarding this post then feel free to comment. In upcoming tutorial, you will get more kivy tutorials till then stay connected with Simplified Python. Thanks Everyone.
- Python Tic Tac Toe Using Artificial Intelligence
- Python MongoDB Connection – An Introduction To MongoDB With Python
- Sublime Run Python – Running Python Programs On Sublime Text 3