Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. from tkinter import *
  2. from random import *
  3. turns=10
  4. points=0
  5. def onclick():
  6. global turns,points
  7. iscat=randint(1,11)
  8. btn.configure(state="disabled")
  9. if iscat==1:
  10. btn.configure(background="blue")
  11. statlabel.configure(text="You found a cat!")
  12. points=points+1
  13. else:
  14. btn.configure(bg="red")
  15. statlabel.configure(text="It's empty! Hurry, or all the cats will die!")
  16. turns=turns-1
  17. root=Tk()
  18. root.title("Catsweeper")
  19. root.configure(background="black")
  20. frame=Frame(root)
  21. frame.configure(bg="black")
  22. Grid.rowconfigure(root, 0, weight=1)
  23. Grid.columnconfigure(root, 0, weight=1)
  24. frame.grid(row=0, column=0)
  25. grid=Frame(frame)
  26. grid.grid(column=0, row=7, columnspan=2)
  27. Grid.rowconfigure(frame, 7, weight=1)
  28. Grid.columnconfigure(frame, 0, weight=1)
  29. chosenx=int(input("How many rows? "))
  30. choseny=int(input("How many columns? "))
  31. for x in range(1,chosenx+1):
  32. for y in range(1, choseny+1):
  33. btn=Button(frame, command=onclick, state = "normal")
  34. btn.grid(column=x, row=y)
  35. statlabel=Label(frame, text="", background="red", fg="white")
  36. statlabel.grid(column=choseny+1)
  37. if turns==0:
  38. statlabel.configure(text="GAME OVER")
  39. btn.configure(state="disabled")
  40. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement