In this Python and Kivy article we want to learn about Getting Started with Kivy in Python, so Kivy is free and open source Python library for developing multi touch applications with natural user interface. Kivy allows you to develop apps that runs on Windows, macOS, Linux, Android and iOS with single codebase. in this article we walk you through the process of getting started with Kivy in Python.
Getting Started with Kivy in Python
First of all we need to install Kivy and you can use pip for Python Kivy installation
1 |
pip install kivy |
Now let’s create our basic gui application with Python and Kivy
1 2 3 4 5 6 7 8 9 |
from kivy.app import App from kivy.uix.button import Button class TestApp(App): def build(self): return Button(text='GeeksCoders') TestApp().run() |
So now let’s describe the code line by line, These lines import App class from the kivy.app module and the Button class from the kivy.uix.button module. App class is the base class for creating Kivy applications, and Button class is builtin Kivy widget that displays a button.
1 2 |
from kivy.app import App from kivy.uix.button import Button |
This line defines a class called TestApp that extends from the App class.
1 |
class TestApp(App): |
This method is called when the application starts and returns root widget of the application. in this case we have created a Button widget and returns it as the root widget.
1 2 |
def build(self): return Button(text='GeeksCoders') |
This line creates an instance of the TestApp class and calls its run method to start the application.
1 |
TestApp().run() |
If you run the code you will see big Python Kivy Button in the GUI Window.
So in this article we have covered the basics of getting started with Kivy in Python. we have explained how to install Kivy and how to create basic Kivy application. Kivy provides different builtin widgets and layout managers that can be used to create complex multitouch applications. with Kivy, you can build applications that run on multiple platforms with single codebase.
Learn More on Kivy
- Introduction to Python Kivy
- How to Integrate Yahoo Finance with Python Kivy
- How to Build Music Player with Kivy
- Build Android Application with Python Kivy
- How to Integrate Matplotlib with Python Kivy
- How to Integrate Pandas with Python Kivy
- Building Cross Platform GUI Applications with Python Kivy