Only last variable passed for callback function
<p>I am trying to generate callback functions with a variable parameter for an array of buttons in Tkinter, but the problem is that only the last item is passed for all the callback functions. For instance, I have something like:
</p>

<pre><code>a = [0, 1, 2]
btn = []
for i in range(0,3):
    btn.append(Button(frame, text='something', command=lambda: funct(a[i])))
</code></pre>

<p>For each button in the btn list, the last item in the <code>a</code> list, <code>2</code>, is passed to the function <code>funct()</code>. However, what I want is <code>a[0]</code> to be passed to <code>funct()</code> for the first button, <code>a[1]</code> for the second button, and so on. How do I go about fixing this problem?</p>
