I have been writing a piece of software that keeps track of homework, written in python. I will give a small snippet which displays all homework's.
def delHomework(homework,element,HLabel,HDelete):
del homework.get(element)
HLabel.destroy()
HDelete.destroy()
row = 0 #keeps track on which height everything is inserted
for i in homeworks: #homeworks is a list of all homework's
HLabel = Label(text=i) #displays the homework
HLabel.grid(column=0,row=row)
HDelete = Button(text="delete",command=lambda:
delHomework(homework,i,HLabel,HDelete)
#is the button to delete the homework
HDelete.grid(column=1,row=row)
row += 1
The problem is that even though it all displays correctly, when you try delete any homework, the last is deleted instead of the associated one because the lambda is referencing the newest sate of the variable instead at that iteration and I can't figure out how to make it work. Hope this question makes sense.