Implementing a switch case statement that uses multiple arguments to validate register input in python tkinter
I would do it something like this:
def checkpassword(p: str, p2 : str): length=len(p) conditions=[p != p2 ,' ' in p , p == '' , length<=8,length>=20] errormsg=["Passwords do not match.", "Password cannot contain blank.", "Password cannot be blank", "Password is less than 8 characters", "Password is more than 20 characters"] return '\n'.join([dtext for func,dtext in zip(conditions,errormsg) if func is True])def checkuser(u : str): length = len(u) conditions=[checkinfile(u),' ' in u, u == '', length<=8,length>=20] errormsg=["Username already exists.", "Username cannot contain blank.", "Username cannot be blank.", "Username is less than 8 characters", "Username is more than 20 characters"] return '\n'.join([dtext for func,dtext in zip(conditions,errormsg) if func is True])def checkinfile(u : str): with open("accounts_list") as f: if u in f.read(): return True return Falsedef validate_and_submit(): u = register_entry_username.get() p,p2 = register_entry_password.get(), confirm_entry_password.get() erroruser, errorpassword = checkuser(u),checkpassword(p,p2) if any([erroruser,errorpassword]): show_bad_input(erroruser + errorpassword) else: perform_registration(u,p)def perform_registration(u, p): ''' do wheatever is needed when all contitions are met'''