The document discusses how to set up and use Kivy, an open source Python framework for developing multi-touch applications. It covers installing Kivy, basic components like App and widgets, different layouts, making a simple "Hello World" app, using the kv language to separate design from code, and packaging the app into an Android application.
2. 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
6. Hello World
f r o m k i v y . a p p i m p o r t A p p
f r o m k i v y . u i x . f l o a t l a y o u t i m p o r t F l o a t L a y o u t
f r o m k i v y . u i x . b u t t o n i m p o r t B u t t o n
f r o m k i v y . u i x . l a b e l i m p o r t L a b e l
c l a s s M y A p p ( A p p ) :
t i t l e = ' H e l l o W o r l d '
d e f b u i l d ( s e l f ) :
s e l f . a p p w i n d o w = F l o a t L a y o u t ( )
b u t t o n = B u t t o n ( t e x t = ' C l i c k H e r e ' )
b u t t o n . b i n d ( o n _ r e l e a s e = s e l f . b u t t o n p r e s s )
s e l f . a p p w i n d o w . a d d _ w i d g e t ( b u t t o n )
r e t u r n s e l f . a p p w i n d o w
d e f b u t t o n p r e s s ( s e l f , * a r g s ) :
s e l f . a p p w i n d o w . c l e a r _ w i d g e t s ( )
s e l f . a p p w i n d o w . a d d _ w i d g e t ( L a b e l ( t e x t = ' H e l l o W o r l d ! ' ) )
i f _ _ n a m e _ _ = = ' _ _ m a i n _ _ ' :
g l o b a l m y a p p
m y a p p = M y A p p ( )
m y a p p . r u n ( )
7. The ‘kv’ Language
class MyButton(Button):
def __init__(self,**kwargs):
super(MyButton,self).__init__(**kwargs)
<MyButton>:
size_hint_x: None
size_hint_y: None
In the kv file:
In the python file:
8. Packaging the app
There are two ways to package the
app:
1. Manually using python-for-android
2.
3. Automatically using buildozer