I am currently trying to create a loop that would bind event-action couples in a dict. The callback function simply calls the action function and prints the parameters.
for binding, action in self.keyMap.revMap.items() :
print binding, action
self.top.bind(binding,
lambda event : self.callback(event, self.actionRep.__class__.__dict__[action]))
print self.top.bind()
At the binding, I get these logs :
<Escape> toggleMenu -------------generated by the line "print binding, action"
<Return> toggleChat -------------generated by the line "print binding, action"
('<Key-Return>', '<Key-Escape>', '<Key>') ---generated by the line "print self.top.bind()"
The event-action couples are correct. However, when the events occur, I have this :
<Tkinter.Event instance at 0x0000000002BB3988> <function toggleChat at 0x0000000002B60AC8>
<Tkinter.Event instance at 0x0000000002BB3948> <function toggleChat at 0x0000000002B60AC8>
that is, both the escape and the return event seem to be bound to toggleChat...
I have little experience of lambda expressions, but I would expect that a new nameless function is created for each of the loops. Am I wrong there ? If not, where could the problem be ?
Thanks in advance for insights.