I want to create tkinter buttons in bulk by using a for loop and the exec function but when i set the command it keeps on calling the function for the last piece in my database
for i in FirstFloor:
exec('room_%d = CreateRoom(FirstFloor[i]["name"])'%index)
exec('lbl_%d = Button(window, text=FirstFloor[i]["name"], command=lambda: move(FirstFloor[i]["x"], FirstFloor[i]["y"]), bg="light grey")'%index)
exec('lbl_%d.grid(column=FirstFloor[i]["x"], row=FirstFloor[i]["y"], columnspan=FirstFloor[i]["xspan"], rowspan=FirstFloor[i]["yspan"])'%index)
if FirstFloor[i]["locked"] == True:
exec('lbl_%d.config(state="disabled", bg="red")'%index)
index += 1
When i run this piece of code and click a button no matter which button i press it keeps going to same object