I have a loop which creates a TKinter-button for each object in a list. I want each button to pass its corresponding object to a function when pressed.
buttonlist = []
for i in list:
buttonlist.append(Button(root, text=i.name, command=lambda: somefunkyfunc(i)))
[i.pack() for i in buttonlist]
currently each button is passing the last object in the list to the function, which was not intended.
How can i make this work?