2016-11-22 124 views
0

带有无法在我手中修复的错误。我找到一个已定义的变量,它已被打开我希望页面关闭,所以不是所有的窗口都打开,但是当我加载新的用户屏幕后,他们已经完成填充新的用户细节,我把一个按钮,它将重定向它们到existingUserEntry页面,它说它不能调用该按钮,需要任何帮助,谢谢?无法调用“按钮”命令:应用程序已被销毁

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) 

回答

1
def existingUserEntry(): 
    intitialScreen.destroy() 
    .... 
    newUserScreen = Button(intitialScreen,...) 

你在你的方法开始摧毁你的intitialScreen然后试图将一个按钮,这会导致错误的末尾添加到该容器中。您需要为您的小部件选择现有的。

而且,请注意,

  • 不要创建多个Tk()实例。如果您想要另一个窗口(例如弹出窗口),请使用Toplevel()而不是Tk()。 (这个代码中只有一个Tk(),但感觉就像你的实际代码中有更多)

  • 如果你不知道你到底在做什么,你很可能不想在任何地方使用mainloop()在程序结束时。

相关问题