有一个错误,无法修复我的手。我在打开后找到一个已定义的变量我希望页面关闭所以不是所有的窗口都打开但是当我加载新的用户屏幕后,当我们填写了新的用户详细信息时,我将一个按钮放入其中以重定向它们到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)
答案 0 :(得分:1)
def existingUserEntry():
intitialScreen.destroy()
....
newUserScreen = Button(intitialScreen,...)
您正在方法开头销毁intitialScreen
,然后尝试在结尾处向该容器添加一个导致错误的按钮。您需要为小部件选择现有的一个。
另外,请注意,
不要创建多个Tk()
个实例。如果您想要其他窗口(例如弹出窗口),请使用Toplevel()
代替Tk()
。 (此代码中只有一个Tk()
,但感觉您的实际代码中有更多内容)
如果您不知道自己到底在做什么,那么您很可能不希望在程序结束时的任何地方使用mainloop()
。