title: How is Tkinter handling lambda after binding event?
body: <p>I am trying to write some code that will send the value of an <code>Entry</code> box to a function based on a binding. I can technically get the behavior I want in the code below, but I'm a) not sure why it works and b) am quite sure I am not doing this in the most pythonic way. I'm pretty sure I'm misunderstanding the <code>event</code> or <code>lambda</code> or both.</p>
  
  <p>In the code below the <code>Entry</code> box called <code>input_box1</code> when the binding triggers, the <code>inp_var1.get()</code> code only gets the default value, not anything that has been entered into the box. In other words, the <code>test1</code> function will print...</p>
  
  <blockquote>
    <p>Test1 Foo</p>
  </blockquote>
  
  <p>... no matter what you type into the entry.</p>
  
  <p>The binding on <code>input_box2</code> works exactly as I expect. I type anything in there and click somewhere else and it prints the new entry. However I don't understand why my <code>lambda</code> doesn't want an <code>event</code> or why I need to repeat the <code>inp_var2.get()</code> call.</p>
  
  <p>If anyone knows what's going under the hood I'd love to hear it! Here's the code:</p>
  
  <pre><code>from tkinter import *
  from tkinter import ttk
  
  def test1(event, i):
      print('Test1', i)
  
  def test2(event, i):
      print('Test2', i)
  
  root = Tk()
  title_label = Label(root, text='This does not work!')
  title_label.grid(column=0, row=0)
  
  inp_var1 = StringVar(value='Foo')
  input_box1 = Entry(root, textvariable=inp_var1)
  input_box1.grid(column=0, row=1)
  
  inp_var2 = StringVar(value='Bar')
  input_box2 = Entry(root, textvariable=inp_var2)
  input_box2.grid(column=0, row=2)
  
  input_box1.bind('&lt;FocusOut&gt;', lambda event, i=inp_var1.get(): test1(event, i))
  input_box2.bind('&lt;FocusOut&gt;', lambda i=inp_var2.get(): test2(i, inp_var2.get()))
  
  root.mainloop()
  </code></pre>