Check the entry after the user has entered a value
<p>I wrote a graphical interface using Tkinter with Python 3.4. In my script, I am using ttk.Entry to generate a input space where the user can enter a value.</p>

<p>Is it possible to do an action when the user has finished tipping e.g. call a function? I though about using a button if it was not possible.</p>

<p>Here is a extract of the code:</p>

<pre><code>ttk.Label(mainframe, text="Enter your data path", font=('Times', '14', 'bold italic')).grid(column=1, row=2, sticky=E)

path_frame = StringVar()
input_path_frame = ttk.Entry(mainframe, width=100, textvariable=path_frame)
input_path_frame.grid(column=2, row=2, columnspan=2, sticky=(N))
</code></pre>

<p>I would like to have a event when the 'input_path_frame' is fullfill.</p>

<p>Thank you for your time</p>

<p>You can add a <code>FocusOut</code> event manager function. This event-manager would execute as soon as the user has finished typing in the field and moved to something else:  </p>

<pre><code>input_path_frame.bind( '&lt;FocusOut&gt;',
    lambda e, strvar=path_frame: check_field(e, strvar)
  )
# check_field function would be executed as soon as the focus leaves the field
</code></pre>

<p>Here <code>check_field</code> function would be used to check if the <code>input_path_frame</code> field is empty or not.<br>.<br>
It would be something like this:</p>

<pre><code>def check_field(e, strvar):
  # do stuff
  # check if empty
  # run tests etc
  return strvar.get()
</code></pre>

<p>If you want to get result keys simultaneously, you can nest two event managing functions like <code>&lt;FocusIn&gt;</code> and <code>&lt;Key&gt;</code>. And can unbind the <code>&lt;key&gt;</code> at <code>&lt;FocusOut&gt;</code>:</p>

<pre><code>input_path_frame.bind("&lt;FocusIn&gt;", lambda e: key_bind_func)
input_path_frame.bind("&lt;FocusOut&gt;", lambda e: key_unbind_func)
</code></pre>

python python-3.x tkinter