【发布时间】:2014-03-17 11:53:55
【问题描述】:
您好,我想弄清楚我的代码有什么问题。我正在尝试制作一个密码应用程序,当我单击一个按钮时,当两个密码匹配时,它将打开一个窗口以插入一个配方,如果它们不匹配,那么它将打开一个错误对话框。但是,当我尝试运行它时,它不断出现错误,提示未定义密码。请问有人可以帮忙吗?
def password_screen():
password = Tk()
password.title("Password")
lbl1 = Label(password, text="Please enter the password to access the program's code.")
lbl1.grid(row = 0, column = 0, sticky=W)
Label(password, text = "Password").grid(row = 1, column = 0, sticky = W)
Label(password, text = "Repeat Password").grid(row = 2, column = 0, sticky = W)
btna = Button(password, text = "Continue", command=GetValue)
btna.grid(row = 2, column = 2, padx = 5)
e4 = Entry(password)
e5 = Entry(password)
e4.grid(row=1, column=1)
e5.grid(row=2, column=1)
def GetValue():
global e4, e5
e4 = Entry(password)
e5 = Entry(password)
pass1 = e4.get()
pass2 = e5.get()
if pass1 == pass2:
btna.configure(command=insert_new_recipe)
else:
btna.configure(command=dialog)
【问题讨论】:
-
password是password_screen中的一个局部变量。无法从GetValue访问。 -
那我该怎么解决这个问题?