Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. class grid():
  2. def __init__(self):
  3. self.root= Tk()
  4.  
  5. Label(self.root,text="TIC TAC TOE").pack(pady=10,padx=10)
  6.  
  7. self.rows=[]
  8.  
  9. for i in range(0,3):
  10. self.rows.append(Frame(self.root,borderwidth=2))
  11. self.rows[i].pack(side=TOP)
  12. self.resultF=Frame(self.root,borderwidth=2)
  13. self.resultF.pack(side=BOTTOM)
  14.  
  15. self.resultL=Label(self.resultF,text=" Game on! ",justify=CENTER)
  16. self.resultL.pack(pady=10,padx=10)
  17.  
  18. self.matrix=[[],[],[]]
  19. for i in range(0,3):
  20.  
  21. for j in range(0,3):
  22. self.matrix[i].append(Button(self.rows[i],text=str(i)+str(j),state=ACTIVE,height=10,
  23. width=20,
  24. command=lambda : self.Click(i)
  25. ,padx=2,pady=2))
  26. print i
  27. self.matrix[i][j].pack(side=LEFT)
  28.  
  29.  
  30. mainloop()
  31.  
  32. def Click(self,coords):
  33. print coords
  34. for i in range(0,3):
  35. for j in range(0,3):
  36. if(i*10+j == coords):
  37. print i,j
  38. self.matrix[i][j]['state']='disabled'
  39.  
  40.  
  41.  
  42. grid()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement