The buttons are being created in a larger loop iterating through i then j with the following code:
btn[i][j] = Button(lbl_frm, width=24, height=24, image=unchecked_img,
command=lamda:change_btn_img(btn[i][j]),relief=SOLID)
global state
state = "unchecked"
btn[i][j].place(relx=.5, rely=.5, anchor='c')
with the function to change the configuration of the button:
def change_btn_img(btn):
global state
if state == "checked":
btn.configure(image=unchecked_img)
state = "unchecked"
elif state == "unchecked":
btn.configure(image=checked_img)
state = "checked"
However, this isn't working as if I click any button it only changes the image of btn[i][j] where i and j were values reached in the last iteration of the loop. The buttons are used to form a grid, and in this case clicking any changes the last element in the last row. Is there any way to make it so that the i and j used when declaring the command upon creation of the button are fixed to that specific button?