1. What is kivy?

Kivy is a free and open source library for Python, useful for building touch applications with a natural user interface. This library works on Android, iOS, GNU / Linux, OS X and Windows. It is distributed free of charge and under the MIT license. Kivy is the main framework developed by the Kivy organization, in parallel with Python-for-Android2, Kivy iOS, as well as several other libraries intended to be usable on all these platforms. The framework contains all the elements to build applications and in particular:

  1. Extended input functions for the mouse, keyboard, tangible user interfaces, as well as multi-touch events generated by these different devices.
  2. a graphics library based only on OpenGL ES2, and using Vertex Buffer Objects and shaders.
  3. a wide range of widgets supporting multi-touch.
  4. an intermediate language (Kv3), to easily build custom widgets.

2. Installation of the Kivy framework

2.1. Make sure you have the latest version of the pip utility:

python -m pip install --upgrade pip wheel setuptools

2.2. Install the necessary 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

2.3. Install the Kivy framework:

python -m pip install kivy

2.4. Install the Kivy examples package (optional):

python -m pip install kivy_examples

3. First program with Kivy framework

3.1 First kivy window displaying a label

Using your Python IDE, create a new project and name it for example firstApp.py, then insert the two lines of code to import the app and widget libraries:

# import the main class App
from kivy.app import App
# import of the Widget class which is used to create widgets
from kivy.uix.widget import Widget

Create a class named myApp which inherits from the App class, and insert within which the build() function. Then add within the build() function the code of a label displaying the text: 'Hello World!' and apply at the end of the code the run() method which allows you to launch the application:

final code:

# import the main class App
from kivy.app import App
# import of the Label class
from kivy.uix.label import Label
class myApp(App):
def build(self):
lbl=Label(text='Hello World!')
return lbl
myApp().run()

Younes Derfoufi
my-courses.net

Leave a Reply