Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import Tkinter
  2. import random
  3. import tkMessageBox
  4.  
  5. window = Tkinter.Tk()
  6.  
  7. secret = random.randint(1, 10)
  8.  
  9. #greeting text
  10. greeting = Tkinter.Label(window, text="Guess the secret number!")
  11. greeting.pack()
  12.  
  13. # guess entry field
  14. guess = Tkinter.Entry(window)
  15. guess.pack()
  16.  
  17. # check guess
  18. def check_guess():
  19. if int(guess.get()) == secret:
  20. result_text = "CORRECT!"
  21. elif int(guess.get()) > secret:
  22. result_text = "WRONG! Your guess is too high."
  23. else:
  24. result_text = "WRONG! Your guess is too low."
  25.  
  26. tkMessageBox.showinfo("Result", result_text)
  27.  
  28. # submit button
  29. submit = Tkinter.Button(window, text="Submit", command=check_guess) # check_guess, not check_guess()
  30. submit.pack()
  31.  
  32. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement