'when validating an entry in Tkinter using focusout how do i get the next entry validate method not to trigger when focus is on it

import tkinter
from tkinter import *
   
def validate_name(name):
    if len(name) > 2 and not name.isdigit():
        name_textBox.config(bg='#C4C4C4')      
        return True
    elif any(ch.isdigit() for ch in name):
        name_textBox.config(bg='#F56B6F')                
        name_textBox.delete(0, END)  
        name_textBox.focus_set() 
        return False  
    elif len(name) == 0:                    
        name_textBox.config(bg='#F56B6F')
        name_textBox.delete(0, END)  
        name_textBox.focus_set() 
        return False
    elif len(name) <= 2:
        name_textBox.config(bg='#F56B6F')
        name_textBox.delete(0, END)  
        name_textBox.focus_set() 
        return False
    else:                  
        name_textBox.config(bg='#F56B6F') 
        name_textBox.delete(0, END)  
        name_textBox.focus_set() 
        return False                  
                      
def validate_lname(lname):     
    if len(lname) > 2 and not lname.isdigit():
        lname_textBox.config(bg='#FFFFFF')      
        return True
    elif any(ch.isdigit() for ch in lname):
        lname_textBox.config(bg='#F56B6F')                
        lname_textBox.delete(0, END)  
        lname_textBox.focus_set() 
        return False  
    elif len(lname) == 0:                    
        lname_textBox.config(bg='#F56B6F')
        lname_textBox.delete(0, END)  
        lname_textBox.focus_set() 
        return False
    elif len(lname) <= 2:
        lname_textBox.config(bg='#F56B6F')
        lname_textBox.delete(0, END)  
        lname_textBox.focus_set() 
        return False
    else:                  
        lname_textBox.config(bg='#F56B6F')                
        lname_textBox.delete(0, END)  
        lname_textBox.focus_set() 
        return False   

                      

root = Tk()  
name_textBox = Entry(root)
name_textBox.grid(row=0, column=0)
vcmd = root.register(validate_name)
name_textBox.config(validate="focusout", validatecommand=(vcmd,'%P'))
    
    
lname_textBox = Entry(root)
lname_textBox.grid(row=1, column=0)
vcmd1 = root.register(validate_lname)
lname_textBox.config(validate="focusout",validatecommand=(vcmd1,'%P'))
    
root.mainloop()

Am new to Python and Tkinter i want to trigger validation on an of a app, where entries in a form are adjacent to each other. After input into entry if i move my cursor to another entry my app freezes. How do i fix it I want each entry to validate and for the App to stop freezing. I didnt get any error out of it, it simply just froze. I have no idea why it is happeing. I have have searched and havent seen any answer about here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source