I want to change the color of the button when its pressed.
map = []
for y in range(20):
for x in range(20):
map.append(0)
def button_map():
btn_c = ""
if map[x+20*y] == 1:
btn_c ="red"
elif map[x+20*y] == 2:
btn_c ="blue"
elif map[x+20*y] == 0:
btn_c ="orange"
return btn_c
def button_map_set(x, y):
if map[x+20*y] == 1:
map[x+20*y] = 0
elif map[x+20*y] == 0:
map[x+20*y] = 1
main = Tk()
frame1 = Frame(main)
frame1.pack()
for y in range(20):
for x in range(20):
I have tested this
def test():
button_map_set(x, y)
this
test = button_map_set(x, y)
and this
btn.bind("<btn>", button_map_set(x, y)
btn = Button(framex, command = test, bg = button_map())
main.mainloop()
what happens: it executes when declared, but not when pressed