I have a function, say foo and it's supposed to bind an event
    def foo:
         for x in widget_list:
              widget.config(command = lambda: self.function(widget_list.index(x))
    def function(index):
         do something here....
         print index
The widget list contains buttons, and whenever I click corresponding buttons, they're supposed to print to the IDLE their index, but what happens is that all the buttons I click end up printing the last index of widget_list. I'm guessing that while for iterates, the argument of the function also changes thus only the last index is preserved. Is there anyway to bind the previous indexes to the button?
 
    