Lambda function: why do I need a parameter in eventhandlers but not in Button-commands?
<p>In the following case of a Python lambda call, I need to set a parameter for the function to work properly:</p>

<pre><code>name = Entry(self.new_jobtile, width=30)
...
name.bind('&lt;Return&gt;', lambda x:self.create_tile(name.get()))
</code></pre>

<p>However, if I use a Button instead, the very same lambda call works without the "x" parameter:</p>

<pre><code>Button(self.new_jobtile, text="OK", command=lambda: self.create_tile(name.get()), width=4, height=2).pack(side=BOTTOM, pady=3, padx=5)
</code></pre>

<p>I really don't understand why?</p>

<p>I have no idea about API of that <code>Entry</code> and <code>Button</code> classes, but here is my guess. Probably <code>bind</code> method of the <code>Entry</code> requires a callback function (your lambda) to has one parameter, in other words, somewhere in the <code>bind</code> method can be a piece of code like this:</p>

<pre><code>def bind(self, an_argument, yourcallback):
    yourcallback(something)
</code></pre>

<p>You just ignore this parameter, but you can figure out what that <code>bind</code> method passes to your callback:</p>

<pre><code>name.bind('&lt;Return&gt;', lambda x:self.create_tile(str(x) + " " + name.get()))
</code></pre>

<p>From the other side, the <code>pack</code> method does not pass a parameter. So your lambda works in that case. </p>

python lambda