Aquí está el código, pero al ejecutarlo solamente cambia el color del último botón sin importar cual presione cuando llamo a la funcion press
con command
:
from tkinter import *
from create_cells import *
class Board():
def __init__(self):
self.Br = Tk()
self.Br.title("Board")
self.boardFrame = Frame(self.Br).grid(column=0,row=0)
# The next instructions create a new board with buttons to chose a cell
for self.r in range(0,20):
for self.c in range(0, 40):
self.newButton = Button(self.Br,text="",command=self.press)
self.newButton.grid(row = self.r, column = self.c)
self.startButton = Button(self.Br,text="Start",bg ="indian red").grid(row=40, column=0,columnspan=10, sticky= W+E)
self.restartButton = Button(self.Br,text="Restart",bg ="indian red").grid(row=40, column=20, columnspan=10, sticky= W+E)
self.pauseButton = Button(self.Br,text="Pause",bg ="indian red").grid(row=40, column=10, columnspan=10, sticky= W+E)
self.exitButton = Button(self.Br, text="Exit", bg ="indian red", command=self.Br.destroy).grid(row=40, column=30, columnspan=10, sticky= W+E)
self.Br.mainloop()
def press (self, *args):
self.newButton.configure(bg = "gold")