1

I want to have a function called, each time when an entry in my tkinter window is changed. Because I don't want the function to be called while the used is still typing, I chose "focusout" for the validate attribute. For clarification, I got the "focusout" idea from another thread, so I am not exactly sure what it does.

The function validate is called once, but never again. Why is that?

Minimum working example below:

 import tkinter as tk


 def validate():
     print("Checked!")


 root = tk.Tk()
 sv1 = tk.StringVar()
 sv2 = tk.StringVar()
 e1 = tk.Entry(root, textvariable=sv1, validate="focusout", validatecommand=validate)
 e2 = tk.Entry(root, textvariable=sv2, validate="focusout", validatecommand=validate)

 e1.pack()
 e2.pack()

 root.mainloop()
Alex V.
  • 180
  • 2
  • 12

2 Answers2

2

The validation function must return True or False, or it will be disabled.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
1

I finally found the answer. The validate function HAS TO RETURN True or False, or else it is turned off after one use.

See this thread: Interactively validating Entry widget content in tkinter

Alex V.
  • 180
  • 2
  • 12