Guest User

Untitled

a guest
Dec 17th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import random
  2. import Tkinter
  3. import tkMessageBox
  4.  
  5. window = Tkinter.Tk()
  6.  
  7. greetings = Tkinter.Label(window, text= "Hello, to Guess the Capital! ")
  8. greetings.pack()
  9.  
  10.  
  11. def main ():
  12. country_capital_dict = {"Austria": "Vienna", "Germany": "Berlin", "Slovenia": "Ljubljana", "Italy" : "Rome", "Spain" : "Madrid"}
  13.  
  14. random_number = random.randint(0, 4)
  15. selected_country = country_capital_dict.keys() [random_number]
  16.  
  17. question_label = Tkinter.Label(window, text = "What is the capital of %s" % selected_country)
  18. question_label.pack()
  19. question_entry = Tkinter.Entry(window)
  20. question_entry.pack()
  21.  
  22.  
  23.  
  24.  
  25. def check_guess():
  26. if question_entry.get() == selected_country:
  27. result_text = "You got it right"
  28.  
  29. else:
  30. result_text = "sorry nice try!"
  31.  
  32. tkMessageBox.showinfo("Entry", result_text)
  33.  
  34.  
  35. submit = Tkinter.Button(window, text = "submit", command = check_guess)
  36. submit.pack()
  37.  
  38.  
  39.  
  40.  
  41. if __name__ == "__main__":
  42. main()
  43.  
  44.  
  45. window.mainloop()
Add Comment
Please, Sign In to add comment