Skip to content

Commit 1152606

Browse files
committed
initial commit: Next step post solution to excercises in step 5 and 6
0 parents  commit 1152606

File tree

25 files changed

+538
-0
lines changed

25 files changed

+538
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is the tutorial created to be followed by PYCON 2014 kivy workshop
2+
you need to have kivy installed and available for this to work.

step1/kv/main.kv

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
BoxLayout
2+
Button
3+
id: but_trouble
4+
text: 'Hello'
5+
Button
6+
text: 'World'

step1/kv/main.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from kivy.app import App
2+
3+
class MainApp(App):
4+
pass
5+
6+
if __name__ == "__main__":
7+
MainApp().run()

step1/pure_python/main.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from kivy.app import App
2+
from kivy.uix.button import Button
3+
from kivy.uix.boxlayout import BoxLayout
4+
5+
class MainApp(App):
6+
7+
def build(self):
8+
but_trouble = Button(text='Hello')
9+
but_lazy = Button(text='World')
10+
root_widget = BoxLayout()
11+
12+
root_widget.add_widget(but_trouble)
13+
root_widget.add_widget(but_lazy)
14+
15+
return root_widget
16+
17+
if __name__ == "__main__":
18+
MainApp().run()

step2/kv/main.kv

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
BoxLayout
2+
id: root_widget
3+
orientation: 'vertical'
4+
GridLayout
5+
rows: 2
6+
cols: 2
7+
Label
8+
text: 'User Name'
9+
TextInput
10+
id: ti_user
11+
Label
12+
text: 'password'
13+
TextInput
14+
id: ti_password
15+
password: True
16+
Button
17+
text: 'OK'

step2/kv/main.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from kivy.app import App
2+
3+
class MainApp(App):
4+
pass
5+
6+
if __name__ == "__main__":
7+
MainApp().run()

step2/pure_python/main.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from kivy.app import App
2+
from kivy.uix.label import Label
3+
from kivy.uix.textinput import TextInput
4+
from kivy.uix.gridlayout import GridLayout
5+
from kivy.uix.button import Button
6+
from kivy.uix.boxlayout import BoxLayout
7+
8+
class MainApp(App):
9+
10+
def build(self):
11+
# create root widget
12+
root_widget = BoxLayout(orientation='vertical')
13+
14+
# create the labels and the textinputs
15+
lbl_user = Label(text='User Name:')
16+
lbl_password = Label(text='Password')
17+
ti_user = TextInput()
18+
ti_password = TextInput(password=True)
19+
20+
# create the containers for the labels and textinputs
21+
grid_user_pass = GridLayout(rows=2, cols=2)
22+
# create the ok button
23+
my_but_is_ok = Button(text='OK')
24+
25+
# add the labels and input fields to the container
26+
grid_user_pass.add_widget(lbl_user)
27+
grid_user_pass.add_widget(ti_user)
28+
grid_user_pass.add_widget(lbl_password)
29+
grid_user_pass.add_widget(ti_password)
30+
31+
# add the grid_container into it's container
32+
root_widget.add_widget(grid_user_pass)
33+
# add the ok button at the bottom of the grid
34+
root_widget.add_widget(my_but_is_ok)
35+
36+
return root_widget
37+
if __name__ == "__main__":
38+
MainApp().run()

step3/kv/main.kv

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FloatLayout
2+
id: root_widget
3+
BoxLayout
4+
size_hint: None, None
5+
size: dp(400), dp(200)
6+
padding: dp(20), dp(20)
7+
spacing: dp(20)
8+
pos_hint: {'center_x': .5, 'center_y': .5}
9+
orientation: 'vertical'
10+
GridLayout
11+
spacing: dp(20)
12+
rows: 2
13+
cols: 2
14+
Label
15+
text: 'User Name'
16+
TextInput
17+
id: ti_user
18+
multiline: False
19+
Label
20+
text: 'password'
21+
TextInput
22+
id: ti_password
23+
password: True
24+
multiline: False
25+
Button
26+
text: 'OK'
27+
size_hint_y: None
28+
height: dp(48)

step3/kv/main.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from kivy.app import App
2+
3+
class MainApp(App):
4+
pass
5+
6+
if __name__ == "__main__":
7+
MainApp().run()

step3/pure_python/main.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from kivy.app import App
2+
from kivy.uix.label import Label
3+
from kivy.uix.textinput import TextInput
4+
from kivy.uix.floatlayout import FloatLayout
5+
from kivy.uix.gridlayout import GridLayout
6+
from kivy.uix.button import Button
7+
from kivy.uix.boxlayout import BoxLayout
8+
from kivy.metrics import dp
9+
10+
class MainApp(App):
11+
12+
def build(self):
13+
# create root widget
14+
root_widget = FloatLayout()
15+
box = BoxLayout(orientation='vertical',
16+
size_hint=(None, None),
17+
size=(400, 200),
18+
spacing=dp(20),
19+
padding=dp(20),
20+
pos_hint={'center_x': .5, 'center_y':.5})
21+
22+
# create the labels and the textinputs
23+
lbl_user = Label(text='User Name:')
24+
lbl_password = Label(text='Password')
25+
ti_user = TextInput()
26+
ti_password = TextInput(password=True)
27+
28+
# create the containers for the labels and textinputs
29+
grid_user_pass = GridLayout(rows=2, cols=2, spacing=dp(20))
30+
# create the ok button
31+
my_but_is_ok = Button(text='OK')
32+
33+
# add the labels and input fields to the container
34+
grid_user_pass.add_widget(lbl_user)
35+
grid_user_pass.add_widget(ti_user)
36+
grid_user_pass.add_widget(lbl_password)
37+
grid_user_pass.add_widget(ti_password)
38+
39+
# add the grid_container into it's container
40+
box.add_widget(grid_user_pass)
41+
root_widget.add_widget(box)
42+
# add the ok button at the bottom of the grid
43+
box.add_widget(my_but_is_ok)
44+
45+
return root_widget
46+
if __name__ == "__main__":
47+
MainApp().run()

step4/kv/main.kv

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FloatLayout
2+
id: root_widget
3+
BoxLayout
4+
size_hint: None, None
5+
size: dp(400), dp(200)
6+
padding: dp(20), dp(20)
7+
spacing: dp(20)
8+
pos_hint: {'center_x': .5, 'center_y': .5}
9+
orientation: 'vertical'
10+
GridLayout
11+
spacing: dp(20)
12+
rows: 2
13+
cols: 2
14+
Label
15+
text: 'User Name'
16+
TextInput
17+
id: ti_user
18+
multiline: False
19+
Label
20+
text: 'password'
21+
TextInput
22+
id: ti_password
23+
password: True
24+
multiline: False
25+
Button
26+
text: 'OK'
27+
size_hint_y: None
28+
height: dp(48)
29+
on_release: app.check_user(ti_user.text, ti_password.text)

step4/kv/main.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from kivy.app import App
2+
from plyer import tts
3+
4+
class MainApp(App):
5+
6+
def check_user(self, user, pwd):
7+
if pwd.lower() == 'pyconindia':
8+
tts.speak('Hello {}. Welcome to Pycon India!'.format(user))
9+
if pwd.lower() == 'funny':
10+
tts.speak('Lalu ji ko rabri achi lagti hai')
11+
12+
if __name__ == "__main__":
13+
MainApp().run()

step4/pure_python/main.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from kivy.app import App
2+
from kivy.uix.label import Label
3+
from kivy.uix.textinput import TextInput
4+
from kivy.uix.floatlayout import FloatLayout
5+
from kivy.uix.gridlayout import GridLayout
6+
from kivy.uix.button import Button
7+
from kivy.uix.boxlayout import BoxLayout
8+
from kivy.metrics import dp
9+
from plyer import tts
10+
11+
class MainApp(App):
12+
13+
def build(self):
14+
# create root widget
15+
root_widget = FloatLayout()
16+
box = BoxLayout(orientation='vertical',
17+
size_hint=(None, None),
18+
size=(400, 200),
19+
spacing=dp(20),
20+
padding=dp(20),
21+
pos_hint={'center_x': .5, 'center_y':.5})
22+
23+
# create the labels and the textinputs
24+
lbl_user = Label(text='User Name:')
25+
lbl_password = Label(text='Password')
26+
ti_user = TextInput()
27+
ti_password = TextInput(password=True)
28+
29+
# create the containers for the labels and textinputs
30+
grid_user_pass = GridLayout(rows=2, cols=2, spacing=dp(20))
31+
# create the ok button
32+
my_but_is_ok = Button(text='OK')
33+
my_but_is_ok.bind(on_release=lambda *args: self.check_user(ti_user.text, ti_password.text))
34+
35+
# add the labels and input fields to the container
36+
grid_user_pass.add_widget(lbl_user)
37+
grid_user_pass.add_widget(ti_user)
38+
grid_user_pass.add_widget(lbl_password)
39+
grid_user_pass.add_widget(ti_password)
40+
41+
# add the grid_container into it's container
42+
box.add_widget(grid_user_pass)
43+
root_widget.add_widget(box)
44+
# add the ok button at the bottom of the grid
45+
box.add_widget(my_but_is_ok)
46+
47+
return root_widget
48+
49+
def check_user(self, user, pwd):
50+
if pwd.lower() == 'pyconindia':
51+
tts.speak('Hello {}. Welcome to Pycon India!'.format(user))
52+
if pwd.lower() == 'funny':
53+
tts.speak('Lalu ji ko rabbri, bahoot pasand hai!')
54+
55+
56+
if __name__ == "__main__":
57+
MainApp().run()

step5/1.gif

1.48 MB
Loading

step5/2.gif

604 KB
Loading

step5/3.gif

204 KB
Loading

step5/kv/main.kv

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
ScreenManager
2+
Screen
3+
name: 'screen 1'
4+
BoxLayout
5+
size_hint: None, None
6+
size: dp(400), dp(200)
7+
padding: dp(20), dp(20)
8+
spacing: dp(20)
9+
pos_hint: {'center_x': .5, 'center_y': .5}
10+
orientation: 'vertical'
11+
GridLayout
12+
spacing: dp(20)
13+
rows: 2
14+
cols: 2
15+
Label
16+
text: 'User Name'
17+
TextInput
18+
id: ti_user
19+
multiline: False
20+
Label
21+
text: 'password'
22+
TextInput
23+
id: ti_password
24+
password: True
25+
multiline: False
26+
Button
27+
text: 'OK'
28+
size_hint_y: None
29+
height: dp(48)
30+
on_release: app.check_user(ti_user.text, ti_password.text)
31+
Screen
32+
name: 'screen 2'
33+
NextButt
34+
source: '../1.gif'
35+
on_release: root.current = 'screen 3'
36+
Screen
37+
name: 'screen 3'
38+
NextButt
39+
source: '../2.gif'
40+
on_release: root.current = 'screen 4'
41+
Screen
42+
name: 'screen 4'
43+
NextButt
44+
source: '../3.gif'
45+
on_release: root.current = 'screen 1'
46+
47+
<NextButt@ButtonBehavior+Image>
48+
anim_delay: .1
49+
allow_stretch: True
50+

step5/kv/main.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from kivy.app import App
2+
from plyer import tts
3+
4+
class MainApp(App):
5+
6+
def check_user(self, user, pwd):
7+
if pwd.lower() == 'pyconindia':
8+
tts.speak('Hello {}. Welcome to Pycon India!'.format(user))
9+
if pwd.lower() == 'funny':
10+
tts.speak('Lalu ji ko rabri achi lagti hai')
11+
# load screen 2
12+
self.root.current = 'screen 2'
13+
14+
if __name__ == "__main__":
15+
MainApp().run()

0 commit comments

Comments
 (0)