In: Computer Science
Using Python and Kivy to create a App to ask users 5 questions
with Yes or No button.
1. Are you older than 14?
2. Did you pass 8th or 9th Grade?
3. Are you ready gor highschool?
4. Do you have 4 more years to complete highschool?
5. Are you homeschool?
If the users click Yes for 3 questions or more than you should
get a results page saying this users is in highschool
or else the user is not in highschool. and with pop up a list of
highschool (Make up names).
And if they is in highschool give them a tip of being a student and
if not give them tip before going to highschool.
import kivy
from kivy.app import
App
from kivy.lang import Builder
from kivy.uix.gridlayout import GridLayout
from kivy.uix.popup import Popup
from kivy.properties import StringProperty
Builder.load_string('''
<ConfirmPopup>:
cols:1
Label:
text: root.text
GridLayout:
cols: 2
size_hint_y: None
height: '44sp'
Button:
text:
'Yes'
on_release:
root.dispatch('on_answer','yes')
Button:
text: 'No'
on_release:
root.dispatch('on_answer', 'no')
cols:3
Label:
text: root.text
GridLayout:
cols: 4
size_hint_y: None
height: '44sp'
Button:
text:
'Yes'
on_release:
root.dispatch('on_answer','yes')
Button:
text: 'No'
on_release:
root.dispatch('on_answer', 'no')
cols:5
Label:
text: root.text
GridLayout:
cols: 6
size_hint_y: None
height: '44sp'
Button:
text:
'Yes'
on_release:
root.dispatch('on_answer','yes')
Button:
text: 'No'
on_release:
root.dispatch('on_answer', 'no')
cols:7
Label:
text: root.text
GridLayout:
cols: 8
size_hint_y: None
height: '44sp'
Button:
text:
'Yes'
on_release:
root.dispatch('on_answer','yes')
Button:
text: 'No'
on_release:
root.dispatch('on_answer', 'no')
cols:9
Label:
text: root.text
GridLayout:
cols: 10
size_hint_y: None
height: '44sp'
Button:
text:
'Yes'
on_release:
root.dispatch('on_answer','yes')
Button:
text: 'No'
on_release:
root.dispatch('on_answer', 'no')
''')
class
ConfirmPopup(GridLayout):
text = StringProperty()
def __init__(self,**kwargs):
self.register_event_type('on_answer')
super(ConfirmPopup,self).__init__(**kwargs)
def on_answer(self, *args):
pass
class
PopupTest(App):
def build(self):
content = ConfirmPopup(text='1.Are
you older than 14?')
content.bind(on_answer=self._on_answer)
self.popup = Popup(title="Answer
Question",
content=content,
size_hint=(None, None),
size=(480,400),
auto_dismiss= False)
self.popup.open()
def build(self):
content = ConfirmPopup(text='2.Did
you pass 8th or 9th Grade?')
content.bind(on_answer=self._on_answer)
self.popup = Popup(title="Answer
Question",
content=content,
size_hint=(None, None),
size=(480,400),
auto_dismiss= False)
self.popup.open()
def build(self):
content = ConfirmPopup(text='3.Are
you read gor highschool?')
content.bind(on_answer=self._on_answer)
self.popup = Popup(title="Answer
Question",
content=content,
size_hint=(None, None),
size=(480,400),
auto_dismiss= False)
self.popup.open()
def build(self):
content = ConfirmPopup(text='4.Do
you have 4 more years to complete highschool?')
content.bind(on_answer=self._on_answer)
self.popup = Popup(title="Answer
Question",
content=content,
size_hint=(None, None),
size=(480,400),
auto_dismiss= False)
self.popup.open()
def build(self):
content = ConfirmPopup(text='5.Are
you homeschool?')
content.bind(on_answer=self._on_answer)
self.popup = Popup(title="Answer
Question",
content=content,
size_hint=(None, None),
size=(480,400),
auto_dismiss= False)
self.popup.open()
def _on_answer(self, instance, answer):
if('on_answer','yes'>=3)
print "This user is in highschool "
repr(answer)
self.popup=Popup(Be the best of
yourself)
else
print "The user is not in
highschool", repr(answer)
self.popup=Popup(Slow & Study
wins the race)
if __name__ == '__main__':
PopupTest().run()
Thank you!!! & Don't forget to smile:)