无法调用“按钮”命令:应用程序已被销毁

2024-10-01 15:28:31 发布

您现在位置:Python中文网/ 问答频道 /正文

有一个我无法弥补的错误。我发现一个定义的变量,在它被打开后我想关闭页面,这样不是所有的窗口都是打开的但是当我加载新用户屏幕,一旦他们填写了新的用户详细信息,我放了一个按钮,它将重定向到现有的用户入口页面,这是说它不能调用按钮,任何帮助是必要的谢谢?在

def existingUserEntry():
    intitialScreen.destroy()
    login = False
    global existingUserScreen, usernameEntry, passwordEntry  
    existingUserScreen = Tk() # Set up a screen
    existingUserScreen.title("Existing User Login Screen")# Set a caption
    existingUserScreen.config(bg = "WHITE")# Set the background colour
    existingUserScreen.geometry("350x150")# Set the size of the window
    # Code for the username entry box.    
    usernameLabel = Label(existingUserScreen, text = "User name:")# Username Text box
    usernameLabel.config(bg = "PALE GREEN", font=('Helvetica', 12))# Formatting Features
    usernameLabel.pack()
    usernameEntry = ttk.Entry(existingUserScreen, font = "bold", width = 30)
    usernameEntry.pack()
    # Code for the password entry box.
    passwordLabel = Label(existingUserScreen, text = "Password:")# Password Text box
    passwordLabel.config(bg = "PALE GREEN", font=('Helvetica', 12))# Formatting Features
    passwordLabel.pack()
    passwordEntry = ttk.Entry(existingUserScreen, font = "bold", width = 30, show="*")
    passwordEntry.pack() 
    # Code for the sign in button.
    signInButton = Button(existingUserScreen, text="Sign in", width=10, command=verifyLoginDetails)
    signInButton.pack(expand = 1)# Placement of the Sign In button
    existingUserScreen.mainloop()

#Code for a button to allow new users to login to profile after creating one
    newUserSignInButton = Button(newUserScreen, text=" Back to Login Screen", width=15, command=backToLoginScreen)
    newUserSignInButton.config(height= 1, width= 40)
    newUserSignInButton.pack(expand= 4)
    newUserScreen.mainloop()
    newUserScreen = Button(intitialScreen, text="Existing User Sign In", width=25, command=existingUserEntry)

Tags: thetotext用户boxconfigforcode
1条回答
网友
1楼 · 发布于 2024-10-01 15:28:31
def existingUserEntry():
    intitialScreen.destroy()
    ....
    newUserScreen = Button(intitialScreen,...)

您正在方法的开头销毁您的intitialScreen,然后试图在结尾处向该容器添加一个导致错误的按钮。你需要为你的小部件选择一个现有的。在

另外,请注意

  • 不要创建多个Tk()实例。如果需要另一个窗口(例如弹出窗口),请使用Toplevel(),而不是Tk()。(这段代码中只有一个Tk(),但感觉实际代码中有更多内容)

  • 如果您不知道自己到底在做什么,那么您很可能不想在程序末尾使用^{}

相关问题 更多 >

    热门问题