Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, TextBox, PushButton, Picture, Text
- from random import randrange
- questions = ['What is you name?',
- 'What is your quest?',
- 'What is the air speed velocity of an unladen swallow']
- answers = ['Arthur, King of the Britons',
- 'I seek the Grail',
- 'An African or a European swallow']
- def start():
- if question.index_value < (len(questions)-1):
- question.index_value += 1
- question.value = questions[question.index_value]
- start.text = 'Next'
- check_answer.show()
- else:
- question.value = 'Game over'
- start.hide()
- check_answer.hide()
- def check():
- if input_box.value == answers[question.index_value]:
- question.value = 'Correct'
- else:
- question.value = 'Incorrect'
- app = App(bg = "red" ,title='Quiz', width=400, height=300)
- question = Text(app, text='Ready to start the quiz?')
- question.index_value = -1
- input_box = TextBox(app, text='Answer')
- check_answer = PushButton(app, command = check, text='Check answer')
- check_answer.hide()
- start = PushButton(app, command=start, text='Start')
- app.display()
Add Comment
Please, Sign In to add comment