Home > Mobile >  Why does my python code not continue execution once my function "executelogin()" has been
Why does my python code not continue execution once my function "executelogin()" has been

Time:01-31

I am encountering a problem where my code does NOT continue execution of the rest of the program once my called function, completes execution.

Here is the function that is being called:

def executelogin():
    
    global initiate_game_window
    global checker
    counter = 1
    while counter < 4:
        global login_tk, game, us1_entry, us2_entry, us1_pwd_entry, us2_pwd_entry
        login_tk = Tk(screenName="Login - RollADie")
        titlelabel = Label(text="Welcome to rollaDie", font=('Open Sans', '20'))
        titlelabel.grid(column=0, row=0, sticky=NSEW)
        sublabel = Label(text="Login Below: ", font=('Open Sans', '10'))
        sublabel.grid(column=0, row=1, sticky=NSEW)
        
        us1_label = Label(text="User 1:")
        us1_label.grid(row=2, column=0, sticky=NSEW)

        us1_entry = Entry(width=10, textvariable=us1_uname)
        us1_entry.grid(row=3, column=0, sticky=NSEW)

        us1_pwd_label = Label(text="Password:")
        us1_pwd_label.grid(row=4, column=0, sticky=NSEW)

        us1_pwd_entry = Entry(width=10, show="*", textvariable=us1_pwrd)
        us1_pwd_entry.grid(row=5, column=0, sticky=NSEW)

        us2_label = Label( text="User 2:")
        us2_label.grid(row=6, column=0, sticky=NSEW)

        us2_entry = Entry(width=10, textvariable=us2_uname)
        us2_entry.grid(row=7, column=0, sticky=NSEW)

        us2_pwd_label = Label(text="Password:")
        us2_pwd_label.grid(row=8, column=0, sticky=NSEW)

        us2_pwd_entry = Entry(width=10, show="*", textvariable=us2_pwrd)
        us2_pwd_entry.grid(row=9, column=0, sticky=NSEW)

        def get_credentials():
            global us1_entry, us2_entry, us1_pwd_entry, us2_pwd_entry, top_login
            us1_uname = us1_entry.get()
            us1_pwrd = us1_pwd_entry.get()
            us2_uname = us2_entry.get()
            us2_pwrd = us2_pwd_entry.get()
            print(us1_uname, us1_pwrd, us2_uname, us2_pwrd)
            
            global credentials
            credentials = [us1_uname, us1_pwrd, us2_uname, us2_pwrd]
            top_login.destroy()


        global top_login
        top_login = tk.Toplevel()
        top_login.geometry('1x1 0 0')
        top_login.overrideredirect(True)
        submit_button = Button(text="Submit", command=get_credentials)
        submit_button.grid(row=10, column=0, sticky=NSEW)
        top_login.wait_window(top_login)
        
        us1_auth = False
        us2_auth = False

        if login(credentials[0], credentials[1]) == True:
            us1_auth = True
        else:
            pass

        if login(credentials[2], credentials[3]) == True:
            us2_auth = True
        else:
            pass


        if us1_auth ==  True:
            if us2_auth == True:
                print("Auth POS")
                messagebox.showinfo(message="AUTHORISED")
                login_tk.destroy()
                break
            else:
                print("User 2 AUTH NEG")
                messagebox.showinfo(message="User 2 Denied")
                counter  = 1
                if counter > 3:
                    messagebox.showinfo(message="MAX ATTEMPTS")
                    quit()
                continue
        else:
            print("AUTH USER 1 NEG")
            messagebox.showinfo(message="USER 1 NOT AUTHORISED")
            counter  = 1
            if counter > 3:
                    messagebox.showinfo(message="MAX ATTEMPTS")
                    quit()
            continue
    login_tk.mainloop()

I am not sure why this is not continuing on with the rest of the code as expected.

I'd appreciate any help.

For further reference, there is another Tk object in this file, which is initiated later down.

Thanks şehzade Muhammad Amen Ehsan

Edit:

Below this function is the following code:

top = None
top_roll2 = None
faces = {'1':'\u2680', '2':'\u2681', '3':'\u2682', '4':'\u2683', '5':'\u2684', '6':'\u2685'}
root = Tk(className='RollADice', screenName='RollADice')
title = Label(text='RollADice by. Amen', font=('Open Sans', '20')).grid(row=0, column=0, sticky=NSEW)
round_teller = Label(text='Currently: Round {0}'.format(roundnum))
round_teller.grid(row=1, column=0, sticky=NSEW)
dicelabel = Label(root)

CodePudding user response:

my 2 cents: you are creating a Tk instance within that function, and hence you have an infinite loop that wont finish until you exit from it; that is, until you exit from the login_tk mainloop.

  • Related