Python for Android: Kivy (ongoing)

Kivy is a graphical interface for building mobile interactive based applications with Python.

There are different versions for download, depending on your OS.

For Ubuntu etc. there are some packages that need to be added

sudo add-apt-repository ppa:kivy-team/kivy

sudo apt-get install pkg-config python-setuptools python-pygame python-opengl \ python-gst0.10 python-enchant gstreamer0.10-plugins-good python-dev \ build-essential libgl1-mesa-dev libgles2-mesa-dev cython

Cython also needs to be installed.

Differently run the sudo easy_install kivy command in terminal.

Installation process is a bit complicated but definitely not hard to sustain.

Thereafter, start your editor of choice  and  make a python file with the following  code. For this project and in  order to run Kivy GUI i  am using PyDev for Eclipse.

Kivy app

Created on Jan 19, 2014

@author: nick

from import App

from kivy.uix.scatter import Scatter
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout

class TutorialApp(App):
    def  build(self):
        b = BoxLayout(orientation='vertical')
        t = TextInput(font_size=50,
                      text='enter text!!')
        f =  FloatLayout()
        s = Scatter()
        l = Label(text="Hello World",
        return b

if __name__ == "__main__":

Succeeding the above process will find you playing with a nice application. Mine looks like this.

So next step will be to deploy our app into an apk. In order to do so buildozer  is required which can be easily installed with:

sudo pip install buildozer

It is developed by the kivy devs and uses python-for-android. So buildozer automatically installs Android NDK and Android SDK as well as Python-for-android. It can also push the apk to your device.

buildozer  init

Will create a buildozer.spec file  which we will edit.


And then by running the command below the apk will be created.

buildozer android debug

In order to compile and push the application into your device the additional  argument deploy

You can  download and play with the application here.

No comments:

Post a Comment

Free online chess

View Kapellas Nick's profile on LinkedIn
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License