Design of my game is something like this
I need to develop Strategic tic tac toe(where in each block of tic tac toe we will find a tic tac toe)....so here i created 9 frames and each frame has 9 buttons...
but when i click the button in any frame changes appear only in one frame ie; in (0,2) i know because its the last frame which is to be called..so i need help to rectify the problem...i tried but i did not get it thanks in advance
Here's my code
from Tkinter import *
root = Tk()
root.title("Simple Design")
root.geometry("300x300")
class Design:
count = 0
def __init__(self):
self.duplicates = {}
self.block = {}
self.button = {}
for i in range(3):
for j in range(3):
self.duplicates[i, j] = "."
self.frame()
def frame(self):
for i, j in self.duplicates:
self.block[i, j] = Frame(root, background="blue")
self.block[i, j].grid(row=i, column=j, ipadx=5, ipady=2)
self.button_create(self.block[i, j])
def button_create(self, frame):
for i, j in self.duplicates:
handler = lambda a=i, b=j: self.update(a, b)
self.button[i, j] = Button(frame, command=handler, text=".", height=3, width=5)
self.button[i, j].grid(row=i, column=j)
def update(self, i, j):
if (Design.count % 2 == 0):
self.button[i, j]["text"] = "X"
Design.count += 1
else:
self.button[i, j]["text"] = "O"
Design.count += 1
self.button[i, j]["state"] = "disabled"
print (i, j)
d = Design() # out of class
root.mainloop()