简体   繁体   English

为什么我的 python 代码在我的 function “executelogin()” 执行后不继续执行?

[英]Why does my python code not continue execution once my function "executelogin()" has been executed?

I am encountering a problem where my code does NOT continue execution of the rest of the program once my called function, completes execution.我遇到一个问题,一旦我调用 function 完成执行,我的代码就不会继续执行程序的 rest。

Here is the function that is being called:这是被调用的 function:

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.我不确定为什么没有按预期继续使用代码的 rest。

I'd appreciate any help.我将不胜感激任何帮助。

For further reference, there is another Tk object in this file, which is initiated later down.进一步参考,这个文件里还有一个Tk object,后面开始往下。

Thanks şehzade Muhammad Amen Ehsan谢谢 şehzade Muhammad Amen Ehsan

Edit:编辑:

Below this function is the following code:在这个function下面是如下代码:

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)

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;我的 2 美分:你正在 function 中创建一个 Tk 实例,因此你有一个无限循环,直到你退出它才会结束; that is, until you exit from the login_tk mainloop.也就是说,直到您退出 login_tk 主循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM