I sit, I make tic tac toe, and then there was a problem - I had to change the text of the buttons from other functions, I couldn’t change it, because checking for text gives an error:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__ return self.func(*args) File "C:/Users/Чебупелька/Desktop/Python/tictactoe.py", line 16, in <lambda> c11 = Button(root, text="", command=lambda: c11l(), width=20, height=10) File "C:/Users/Чебупелька/Desktop/Python/tictactoe.py", line 74, in c11l if c11['text'] == '': NameError: global name 'c11' is not defined Code below, help than you can.
from Tkinter import * import tkMessageBox i = 0 def start(): root = Tk() root.geometry("600x600") c00 = Button(root, text="", command=lambda: c00l(), width=20, height=10) c00.grid(row=0, column=0) c01 = Button(root, text="", command=lambda: c01l(), width=20, height=10) c01.grid(row=0, column=1) c02 = Button(root, text="", command=lambda: c02l(), width=20, height=10) c02.grid(row=0, column=2) c10 = Button(root, text="", command=lambda: c10l(), width=20, height=10) c10.grid(row=1, column=0) c11 = Button(root, text="", command=lambda: c11l(), width=20, height=10) c11.grid(row=1, column=1) c12 = Button(root, text="", command=lambda: c12l(), width=20, height=10) c12.grid(row=1, column=2) c20 = Button(root, text="", command=lambda: c20l(), width=20, height=10) c20.grid(row=2, column=0) c21 = Button(root, text="", command=lambda: c21l(), width=20, height=10) c21.grid(row=2, column=1) c22 = Button(root, text="", command=lambda: c22l(), width=20, height=10) c22.grid(row=2, column=2) def rst(): root.destroy() dstr = Button(root, text="Exit", command=lambda: rst(), width=5, height=5) dstr.grid(row=3, column=0) root.mainloop() def c00l(): global i, c00 if c00['text'] == '': c00['text'] = 'X' else: tkMessageBox.showinfo(title="ALARM!!!", message="ENGAGED!")