Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import Tkinter
- import tkMessageBox
- window = Tkinter.Tk()
- greetings = Tkinter.Label(window, text= "Hello, to Guess the Capital! ")
- greetings.pack()
- def main ():
- country_capital_dict = {"Austria": "Vienna", "Germany": "Berlin", "Slovenia": "Ljubljana", "Italy" : "Rome", "Spain" : "Madrid"}
- random_number = random.randint(0, 4)
- selected_country = country_capital_dict.keys() [random_number]
- question_label = Tkinter.Label(window, text = "What is the capital of %s" % selected_country)
- question_label.pack()
- question_entry = Tkinter.Entry(window)
- question_entry.pack()
- def check_guess():
- if question_entry.get() == selected_country:
- result_text = "You got it right"
- else:
- result_text = "sorry nice try!"
- tkMessageBox.showinfo("Entry", result_text)
- submit = Tkinter.Button(window, text = "submit", command = check_guess)
- submit.pack()
- if __name__ == "__main__":
- main()
- window.mainloop()
Add Comment
Please, Sign In to add comment