【发布时间】:2017-01-20 13:05:17
【问题描述】:
我的游戏设计是这样的 我需要开发战略井字游戏(在每个井字游戏块中,我们会找到一个井字游戏)......所以在这里我创建了 9 个框架,每个框架有 9 个按钮...... 但是当我单击任何帧中的按钮时,更改只出现在一帧中,即;在(0,2)中,我知道因为它是要调用的最后一帧..所以我需要帮助来纠正问题......我试过但我没有得到它提前谢谢 这是我的代码
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()
【问题讨论】:
标签: python button tkinter frames