Вам нужен частичный. Частичное - это частично лямбда. Я пытался прочитать о лямбде, но ничего из этого не застряло. Я думаю, лямбда живая. Если мне нужно передать переменную в обратный вызов, я использую лямбда, чтобы объявить, что мне нужна живая (изменяющаяся переменная). В этой ситуации вам нужна живая функция, но переменная stati c для каждой кнопки, поэтому вам понадобится партиал. В приведенном ниже коде, где все глобальные переменные в вашей функции щелчка изменяются вместе с программой каждый раз, когда вы нажимаете btn1, она отправляет функции щелчка ноль, btn2 - единицу и так далее. Я пошел дальше и исправил вашу функцию обратного вызова и функцию робота, которая вызывает себя с помощью метода .after. 1000 - это время в миллисекундах, поэтому вы можете настроить его соответствующим образом.
from tkinter import *
from functools import partial
import random
def click(button_num):
global player_score
global cpu_score
global win
global btn_list
global turn
global player
button = btn_list[button_num]
if button['text'] == ' ':
button.configure(text='O', fg='yellow')
button.configure(state=DISABLED)
player = not player
def robot():
global window
global player_score
global cpu_score
global win
global player
if not player:
button = random.choice(btn_list)
if button['text'] == " ":
button.configure(text='X', fg='green')
button.configure(state=DISABLED)
player = not player
if (btn1['text'] == 'O' and btn2['text'] == 'O' and btn3['text'] == 'O' or
btn4['text'] == 'O' and btn5['text'] == 'O' and btn6['text'] == 'O' or
btn7['text'] == 'O' and btn8['text'] == 'O' and btn9['text'] == 'O' or
btn1['text'] == 'O' and btn5['text'] == 'O' and btn9['text'] == 'O' or
btn3['text'] == 'O' and btn5['text'] == 'O' and btn7['text'] == 'O' or
btn1['text'] == 'O' and btn4['text'] == 'O' and btn7['text'] == 'O' or
btn2['text'] == 'O' and btn5['text'] == 'O' and btn8['text'] == 'O' or
btn3['text'] == 'O' and btn6['text'] == 'O' and btn9['text'] == 'O'):
player_score += 1
win = True
elif (btn1['text'] == 'X' and btn2['text'] == 'X' and btn3['text'] == 'X' or
btn4['text'] == 'X' and btn5['text'] == 'X' and btn6['text'] == 'X' or
btn7['text'] == 'X' and btn8['text'] == 'X' and btn9['text'] == 'X' or
btn1['text'] == 'X' and btn5['text'] == 'X' and btn9['text'] == 'X' or
btn3['text'] == 'X' and btn5['text'] == 'X' and btn7['text'] == 'X' or
btn1['text'] == 'X' and btn4['text'] == 'X' and btn7['text'] == 'X' or
btn2['text'] == 'X' and btn5['text'] == 'X' and btn8['text'] == 'X' or
btn3['text'] == 'X' and btn6['text'] == 'X' and btn9['text'] == 'X'):
cpu_score += 1
win = True
window.after(1000, robot)
window = Tk()
window.title('Tic Tac Toe')
buttons = StringVar()
btn1 = Button(window, text=' ', bg='red', height=4, width=8, command=partial(click, 0))
btn1.grid(row=1, column=0)
btn2 = Button(window, text=' ', bg='blue', height=4, width=8, command=partial(click, 1))
btn2.grid(row=1, column=1)
btn3 = Button(window, text=' ', bg='red', height=4, width=8, command=partial(click, 2))
btn3.grid(row=1, column=2)
btn4 = Button(window, text=' ', bg='blue', height=4, width=8, command=partial(click, 3))
btn4.grid(row=2, column=0)
btn5 = Button(window, text=' ', bg='red', height=4, width=8, command=partial(click, 4))
btn5.grid(row=2, column=1)
btn6 = Button(window, text=' ', bg='blue', height=4, width=8, command=partial(click, 5))
btn6.grid(row=2, column=2)
btn7 = Button(window, text=' ', bg='red', height=4, width=8, command=partial(click, 6))
btn7.grid(row=3, column=0)
btn8 = Button(window, text=' ', bg='blue', height=4, width=8, command=partial(click, 7))
btn8.grid(row=3, column=1)
btn9 = Button(window, text=' ', bg='red', height=4, width=8, command=partial(click, 8))
btn9.grid(row=3, column=2)
btn_list = [btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9]
player = True
player_score = 0
cpu_score = 0
turn = 1
click = False
win = False
robot()
window.mainloop()