Search code examples
pythonuser-interfacetkintereventslistener

Tkinter: How to get event listener when entry box is deselected?


Just the title. I have an entry box that needs to be rounded to 10, but I want it to happen the moment another entry box is selected.

The only event listener I can find to do with tkinter entry boxes is attatching a StringVar and tracing it, but that doesn't seem to do what I want here as I don't want the changes to happen while typing.


Solution

  • You are looking for the <FocusOut> event.

    def some_func(event):
        print("The entry has lost focus")
    entry = tk.Entry(...)
    entry.bind("<FocusOut>", some_func)