When UpdateValues
is called, the lambda expression uses the value of key
as it last existed. In particular, no matter which slider you click, key
will be whatever value was iterated through last in your loop (probably "Kims").
The typical solution for this is to put a default argument on your lambda, so that the value binds early and does not change in the next iteration of the loop.
s=Scale(root, from_=1, to=16, orient="horizontal",\
command= lambda x, key=key:self.UpdateValues(key))
You can confirm that this works by changing the body of UpdateValues
:
def UpdateValues(self, key):
print(key)
When you click the top slider, it prints "Kims", and when you click the bottom slider, it prints "Fred". (Or vice-versa, since the order of iteration of a dict is implementation-dependent)