In this Kivy Tutorial we are going to talk about Introduction & Installation of Kivy, we will have a simple introduction to Kivy and after that we learn about installation process at the end we create a simple example.
What is Kivy ?
Kivy is Open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. Kivy runs on Linux, Windows, OS X, Android, iOS, and Raspberry Pi. you can run the same code on all supported platforms. 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. Kivy is 100% free to use, under an MIT license, The toolkit is professionally developed, backed and used. You can use it in a commercial product. the framework is stable and has a well documented API, plus a programming guide to help you get started.
Installation
You can simply install kivy with pip, if you are using windows. also before installation you need to install the dependency for kivy, after that install kivy.
1 |
pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew |
1 |
pip install kivy |
Now let’s create our first window in Kivy, so this is the code for creating our first basic window in kivy.
1 2 3 4 |
from kivy.app import App app = App() app.run() |
We have imported the App class from kivy, after that we have created the object of our App class, and this App class is the initial point for creating of our window. and after you need to just run your app object. after run you will see this result.
Run the code and this is the result.
So now let’s extend our code and also create a label widget in Kivy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
from kivy.app import App from kivy.uix.label import Label class Window(App): def build(self): return Label(text = '[color=ff3333]Hello[color=3333ff]' 'Kivy Application - Geekscoders.com' ,markup=True,font_size = "30sp") if __name__ == "__main__": window = Window() window.run() |
in the above code you can see that first we have imported our required classes from kivy, basically we are going to use App class with Label class. after that we have created our window class that extends from app class. the app class is the starting point of any kivy application.
This method returns the window content. in this case a simple colorful label saying Hello Kivy Application.
1 2 3 4 |
def build(self): #return Label(text = "Hello Kivy Application", font_size = '20sp') return Label(text='[color=ff3333]Hello[color=3333ff]Kivy Application', markup = True, font_size = '30sp') |
Run the complete code and this is the result.