Python-tkinter,combobox - Passing 2 Parameters Using Lambda Function
Background: A GUI table having a 'skip combobox' widget allowing user to skip current line from executing. Amount of lines in this GUI varies. This 'skip' is created using a for l
Solution 1:
It is very common problem with lambda
in loop.
It doesn't copy value from i
when you create lambda
function but it keeps reference to i
. So all functions have reference to the same variable (the same place in memory) and they get value from i
when they are exceuted.
You have to assign i
to argument in lambda
(for example x=i
) and use this argument x
in your function. This way it will copy current value from i
and use in lambda
function
lambda event, x=i : self.but_callback(event, x)
Post a Comment for "Python-tkinter,combobox - Passing 2 Parameters Using Lambda Function"