这是我试图做的: 我想做一个if语句,说明文本=" o" (单击时更改按钮的文本)禁用按钮。 另一个if语句是计算机将其中一个按钮转到" x"。之后,我想再次启用按钮。
import tkinter as tk
board = tk.Tk()
def change(widget):
widget.config(text='o', command=None)
board.geometry("400x500")
board.title("Board")
a = tk.Button(board, the_part_I_tried_to_change1= text="Open Space")
a["command"] = lambda:change(a)
a.grid(row=0, column = 0)
b = tk.Button(board, the_part_I_tried_to_change2 = text="Open Space")
b["command"] = lambda:change(b)
b.grid(row=0, column = 1)
c = tk.Button(board, text="Open Space")
c["command"] = lambda:change(c)
c.grid(row=0, column = 2)
d = tk.Button(board, text="Open Space")
d["command"] = lambda:change(d)
d.grid(row=1, column = 0)
e = tk.Button(board, text="Open Space")
e["command"] = lambda:change(e)
e.grid(row=1, column = 1)
f = tk.Button(board, text="Open Space")
f["command"] = lambda:change(f)
f.grid(row=1, column = 2)
g = tk.Button(board, text="Open Space")
g["command"] = lambda:change(g)
g.grid(row=2, column = 0)
h = tk.Button(board, text="Open Space")
h["command"] = lambda:change(h)
h.grid(row=2, column = 1)
i = tk.Button(board, text="Open Space")
i["command"] = lambda:change(i)
i.grid(row=2, column = 2)a