Introduction to Kivy ; A Cross-platform Python Framework

Kivy is a graphical user interface opensource 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.

Installation

    Note- Python3 should be installed in your system.

  • Installation in Windows:
    1. Update the pip and wheel before installing kivy by entering this command in cmd-
      python -m pip install --upgrade pip wheel setuptools
    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
    3. Install kivy
      python -m pip install kivy
  • Installation in Linux:
    1. Add the PPA by entering this command in terminal-
       sudo add-apt-repository ppa:kivy-team/kivy
    2. Update your package list using your package manager-
      sudo apt-get update
    3. Install Kivy
      sudo apt-get install python3-kivy

Create an application
There are three steps of creating a application with kivy-

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

Example application:
This is python3 code to make a simple application which shows desired text in the system’s screen-

filter_none

edit
close

play_arrow

link
brightness_4
code

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()

chevron_right


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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.