Download - Kivy - Python UI Library for Any Platform
Introduction to Kivy
Introduction to Kivy
A Cross-Platform Python UI Library
In this Session we shall discuss:
How to setup kivy
Some key features of kivy
Make a simple Hello World application
Introduce the kv language
Package the application for the android market
Setting up Kivy
3 very simple commands:
Add Source
sudo add-apt-repository ppa:kivy-team/kivy
Update
sudo apt-get update
Install Kivy
sudo apt-get install python-kivy
Basic Components of Kivy
App
Widget
ScreenManger
Screen
Layouts
Button
Label
TextInput
Image
Clock
SoundLoader
Animation
Types of Layouts
Anchor Layout
Box Layout
Float Layout
Relative Layout
Grid Layout
Stack Layout
Hello World
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
class MyApp(App):
title = 'Hello World'
def build(self):
self.appwindow = FloatLayout()
button = Button(text = 'Click Here')
button.bind(on_release = self.buttonpress)
self.appwindow.add_widget(button)
return self.appwindow
def buttonpress(self,*args):
self.appwindow.clear_widgets()
self.appwindow.add_widget(Label(text = 'Hello World!'))
if __name__ == '__main__':
global myapp
myapp = MyApp()
myapp.run()
The kv Language
class MyButton(Button):
def __init__(self,**kwargs):
super(MyButton,self).__init__(**kwargs)
:size_hint_x: Nonesize_hint_y: None
In the kv file:
In the python file:
Packaging the app
There are two ways to package the app:
Manually using python-for-android
Automatically using buildozer
Prerequisites for manual packaging:
Build-Essential and others:
sudo apt-get install build-essential patch git-core ccache ant python-pip python-dev
Latest Cython:
Pip install upgrade cython
Android SDK
http://developer.android.com/sdk/index.html
Android NDK
http://developer.android.com/sdk/ndk/index.html
Environment variables
export ANDROIDSDK=/path/to/android-sdk
export ANDROIDNDK=/path/to/android-ndk
export ANDROIDNDKVER=rX
export ANDROIDAPI=X
export PATH=$ANDROIDNDK:$ANDROIDSDK/platform-tools:$ANDROIDSDK/tools:$PATH
Manually
Get python-for-android:
git clone git://github.com/kivy/python-for-android
Create distribution:
./distribute.sh -m "kivy"
Build apk:
cd dist/default
./build.py --dir
--name ""
--package
--version
--icon
--orientation
--permission (multiple allowed)
Automatic Packaging using buildozer:
Get buildozer:
git clone https://github.com/kivy/buildozer.git
cd buildozer
sudo python2.7 setup.py install
Create spec file:
cd path/to/app
buildozer init
Build:
buildozer android
Signing and Aligning
(Only for Release apk)
Generate keystore
keytool -genkey -v -keystore path/to/keystore/name.keystore -alias myalias -keyalg RSA -keysize 2048 -validity 10000
Sign using keystore
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ./keystores/com-mydomain-myapp.keystore ./myapp/bin/MyApp-1.0.0-release-unsigned.apk myalias
Zipalign
~/.buildozer/android/platform/android-sdk-21/tools/zipalign -v 4 ./myapp/bin/MyApp-1.0.0-release-unsigned.apk ./myapp/bin/MyApp-1.0.0.apk
All Done!
Congratulations on your first apk!
Thank You!
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
Click to edit Master subtitle style
1/1/2000
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
Click to edit Master text styles
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
Click to edit Master text styles
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
Click to edit Master text styles
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
Click to edit Master text styles
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
Click icon to add picture
Click to edit Master text styles
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
Click icon to add picture
Click to edit Master text styles
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
Click to edit Master text styles
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
Click to edit Master text styles
Click to edit Master text styles
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
Click to edit Master text styles
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
Click to edit Master text styles
Click to edit Master text styles
Click to edit Master text styles
Click to edit Master text styles
Click to edit Master text styles
Click to edit Master text styles
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
Click to edit Master text styles
Click icon to add picture
Click to edit Master text styles
Click to edit Master text styles
Click icon to add picture
Click to edit Master text styles
Click to edit Master text styles
Click icon to add picture
Click to edit Master text styles
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
5/27/2014
5/27/2014
Click to edit Master text stylesSecond level
Third level
Fourth level
Fifth level
5/27/2014