Home > other >  Button Not Adding Up
Button Not Adding Up

Time:11-12

def login_button():
    wrong_value_count = 0
    username = username_entry.get()
    password = password_entry.get()
    if username == user1_username and password == user1_password:
        redirecting_text = canvas.create_text(40, 90, text="Credentials Match, Please Wait While " 
        "We Redirect You To Your Vault", fill="red", anchor=NW)
        canvas.after(2500, lambda: delete_text(redirecting_text))
        print("ESHTA")
    elif username == user2_username and password == user2_password:
        redirecting_text2 = canvas.create_text(40, 90, text="Credentials Match, Please Wait While " 
        "We Redirect You To Your Vault", fill="red", anchor=NW)
        canvas.after(2500, lambda: delete_text3(redirecting_text2))
        print("ESHTA")
    else:
        wrong_value_count  = 1
        if wrong_value_count <= 3:
            print("NOT ESHTA")
            wrong_credentials_text = canvas.create_text(40, 90, text="Wrong Credentials, Try again",
             fill="red", anchor=NW)
            canvas.after(2500, lambda: delete_text2(wrong_credentials_text))
        elif wrong_value_count > 3:
            lock_text = canvas.create_text(40, 90, text="Sorry, You've Reached the Max Number of Trials"
            " Please Try Again Later", fill="red", anchor=NW)
            canvas.after(2500, lambda: delete_text4(lock_text))
        print(wrong_value_count)

Alright, so I'm trying to add to the wrong value count, but every time I click the button, it shows that it's still 1. How do make it add up till it reaches 3 as written?

CodePudding user response:

wrong_value_count must be outside the button because when login_button is called it resets the count to 0, which you don't want.

wrong_value_count = 0
def login_button():
    global wrong_value_count 
    username = username_entry.get()
    password = password_entry.get()
    if username == user1_username and password == user1_password:
        redirecting_text = canvas.create_text(40, 90, text="Credentials Match, Please Wait While " 
        "We Redirect You To Your Vault", fill="red", anchor=NW)
        canvas.after(2500, lambda: delete_text(redirecting_text))
        print("ESHTA")
    elif username == user2_username and password == user2_password:
        redirecting_text2 = canvas.create_text(40, 90, text="Credentials Match, Please Wait While " 
        "We Redirect You To Your Vault", fill="red", anchor=NW)
        canvas.after(2500, lambda: delete_text3(redirecting_text2))
        print("ESHTA")
    else:
        wrong_value_count  = 1
        if wrong_value_count <= 3:
            print("NOT ESHTA")
            wrong_credentials_text = canvas.create_text(40, 90, text="Wrong Credentials, Try again",
             fill="red", anchor=NW)
            canvas.after(2500, lambda: delete_text2(wrong_credentials_text))
        elif wrong_value_count > 3:
            lock_text = canvas.create_text(40, 90, text="Sorry, You've Reached the Max Number of Trials"
            " Please Try Again Later", fill="red", anchor=NW)
            canvas.after(2500, lambda: delete_text4(lock_text))
        print(wrong_value_count)

CodePudding user response:

wrong_value_count = 1 need to be outside the login button. Other wise it will be set to 0

  • Related