I am making a tic tac toe GUI using Tkinter and buttons. Got over some stuff and now I wanted to change the background color when one of the buttons is clicked. The things I did so far I did with lambda but now I can seem to find a way to use the config option of the Button function from Tkinter. I wanted to add that configuration in the which_button function but nothing I could find would help me.
def __init__(self):
super().__init__()
self.button = {}
self.turn = 'X'
for i in range(3):
for j in range(3):
self.button[i, j] = Button(root, width=10, height=5, bg='#E0E0E0', fg='#6D6D6D', command=lambda i=i, j=j: self.which_button(i, j),).grid(row=i, column=j)
def which_button(self, i, j):
label = Label(root, text=self.turn, fg='#E0E0E0', bg='#6D6D6D')
label.grid(row=i, column=j)