Skip to content
Related Articles

Related Articles

Introduction to Kivy ; A Cross-platform Python Framework
  • Last Updated : 13 Jan, 2021

Kivy is a graphical user interface open-source Python library that allows you to develop multi-platform applications on Windows, macOS, Android, iOS, Linux, and Raspberry Pi. The best thing about kivy is, it performs better than HTML5 cross-platform alternatives. 

Note that it is necessary to have Python 3 on your machine to make use of the library.

Installation in Windows: 
 

  • Step 1: Update the pip and wheel before installing kivy by entering this command in cmd- 
     
python -m pip install --upgrade pip wheel setuptools

  • Step 2: Install the dependencies- 
     
python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew
python -m pip install kivy.deps.gstreamer
python -m pip install kivy.deps.angle
  • Step 3: Install kivy.
python -m pip install kivy

It will result in something like the below image:



 

Installation in Linux: 
 

  • Step 1: Add the PPA by entering this command in terminal- 
     
 sudo add-apt-repository ppa:kivy-team/kivy
  • Step 2: Update your package list using your package manager- 
     
sudo apt-get update
  • Step 3: Install Kivy 
     
sudo apt-get install python3-kivy

Create an application 

There are three steps of creating an application with kivy:

  1. Inherit Kivy’s App class which represents the window for our widgets
  2. Create a build() method, which will show the content of the widgets.
  3. And at last calling of the run() method. 
     

Example : 
This is python3 code to make a simple application that shows the desired text on the system’s screen:
 

Python3




import kivy
kivy.require('1.10.0')
  
from kivy.app import App
from kivy.uix.button import Label
  
# Inherit Kivy's App class which represents the window
# for our widgets
# HelloKivy inherits all the fields and methods
# from Kivy
class HelloKivy(App):
  
    # This returns the content we want in the window
    def build(self):
  
        # Return a label widget with Hello Kivy
        return Label(text ="Hello Geeks")
  
helloKivy = HelloKivy()
helloKivy.run()


To run this code open cmd(terminal in Linux) and go through the directory in which the code is saved and type this command- 
 

python file_name.py

 

 

geeks-digest-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :