Same value when iterating.

Hello,

I have the issue that when I run the code:

for i, v in enumerate(list_of_some_sort):
    Button(pageFrame, command=lambda: self.pe_up(i), text='▲').pack(side=LEFT)

and click the button it always feeds 5 into the function (the last value for i). I assueme this is because i is only referanced when the button is clicked but can't seem to fix it. I have tried deep copy but that oes not help.

Any advice would be much appreciated.

Thanks,

Joseph

Posted Aug 25, 2017, 12:42 PM UTC

14
Loading comments…