Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Tkinter
- import random
- import tkMessageBox
- window = Tkinter.Tk()
- secret = random.randint(1, 10)
- #greeting text
- greeting = Tkinter.Label(window, text="Guess the secret number!")
- greeting.pack()
- # guess entry field
- guess = Tkinter.Entry(window)
- guess.pack()
- # check guess
- def check_guess():
- if int(guess.get()) == secret:
- result_text = "CORRECT!"
- elif int(guess.get()) > secret:
- result_text = "WRONG! Your guess is too high."
- else:
- result_text = "WRONG! Your guess is too low."
- tkMessageBox.showinfo("Result", result_text)
- # submit button
- submit = Tkinter.Button(window, text="Submit", command=check_guess) # check_guess, not check_guess()
- submit.pack()
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement