Guest User

Untitled

a guest
Apr 24th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Picture, Text
  2. from random import randrange
  3.  
  4. questions = ['What is you name?',
  5. 'What is your quest?',
  6. 'What is the air speed velocity of an unladen swallow']
  7.  
  8.  
  9. answers = ['Arthur, King of the Britons',
  10. 'I seek the Grail',
  11. 'An African or a European swallow']
  12.  
  13.  
  14. def start():
  15. if question.index_value < (len(questions)-1):
  16. question.index_value += 1
  17. question.value = questions[question.index_value]
  18. start.text = 'Next'
  19. check_answer.show()
  20. else:
  21. question.value = 'Game over'
  22. start.hide()
  23. check_answer.hide()
  24.  
  25. def check():
  26. if input_box.value == answers[question.index_value]:
  27. question.value = 'Correct'
  28. else:
  29. question.value = 'Incorrect'
  30.  
  31. app = App(bg = "red" ,title='Quiz', width=400, height=300)
  32. question = Text(app, text='Ready to start the quiz?')
  33. question.index_value = -1
  34. input_box = TextBox(app, text='Answer')
  35. check_answer = PushButton(app, command = check, text='Check answer')
  36. check_answer.hide()
  37. start = PushButton(app, command=start, text='Start')
  38.  
  39. app.display()
Add Comment
Please, Sign In to add comment