2
Good afternoon friends, I am starting the studies in python and need to do a job using Tkinter. I have 64 buttons and I must change their colors according to the user’s click. It has 6 color options, and when it clicks on one of them, the first of the 64 buttons has to get the color clicked, and so on, until the 64 buttons are colored. However, my code is only changing the last of the 64 buttons, and I am not able to fix it. I will leave the program print and the code. From now on, thank you.
Function called
def getCorAtual(corAtual):
desenho.configure(bg=corAtual)
print(corAtual)
boxCorAtual.configure(bg=corAtual)
Buttons on the left
cor1 = tk.Button(coresWrap, bg='#ffffff', width=10, height=5, command=lambda:
getCorAtual('#ffffff'))
cor1.grid(column=0, row=0)
cor2 = tk.Button(coresWrap, bg='#000000', width=10, height=5, command=lambda:
getCorAtual('#000000'))
cor2.grid(column=1, row=0)
cor3 = tk.Button(coresWrap, bg='#ff0000', width=10, height=5, command=lambda:
getCorAtual('#ff0000'))
cor3.grid(column=0, row=1)
cor4 = tk.Button(coresWrap, bg='#0000ff', width=10, height=5, command=lambda:
getCorAtual('#0000ff'))
cor4.grid(column=1, row=1)
cor5 = tk.Button(coresWrap, bg='#00ff00', width=10, height=5, command=lambda:
getCorAtual('#00ff00'))
cor5.grid(column=0, row=2)
cor6 = tk.Button(coresWrap, bg='#ffff00', width=10, height=5, command=lambda:
getCorAtual('#ffff00'))
cor6.grid(column=1, row=2)
Window creation
containerDesenho = tk.Label(janela, bg='#e3e3e3')
containerDesenho.place(x=200, y=0, width=600, height=800)
tela = tk.Label(containerDesenho, bg='#e3e3e3')
tela.place(width=600, height=700, x=30, y=10)
Buttons that should be colored
for i in range(1, 9):
for j in range(1, 9):
desenho = tk.Button(tela, bg='white', width=8, height=4)
desenho["command"] = lambda x=j, y=i: getBotao(x, y)
desenho.grid(column=j, row=i)
Hi, the idea is that when a button is clicked on the left side all the right side should be colored with the button color pressed?
– William Teixeira
@Williamteixeira exactly that, go coloring from left to right until everyone gets colored.
– joao