[英]Python, tkinter Pop up Window Errors
我编写了一个代码来模拟ATM接口,但是第二阶段似乎有一个错误。 步骤1:要求创建/选择银行帐户步骤2:选择“创建”,将其转到def 创建帐户 :这将打开步骤3:输入帐号:错误(使用的变量似乎未定义?)我看不到问题,也许我是盲目的但我看不出是什么原因引起的错误。 为什么是我的变量:userAnswer总是回来不确定。
import tkinter
x=''
bankList = ['100','101','102','103','104','105','106','107','108','109']
def checkAccount():
number = userAnswer.get()
if number == '1':#in bankList:
print("That Account already exist, try another number.")
else:
bankList.append(number)
print("Your new account has been created!")
def createAccount():
window2 = tkinter.Tk()
window2.title("Creating an Account!")
window2.geometry("400x100")
accountLabel = tkinter.Label(window2, text="Please input the 3 digit number for the Account: ")
userAnswer = tkinter.Entry(window2)
accountButton = tkinter.Button(window2, text="Go", command=checkAccount)
accountLabel.pack()
userAnswer.pack()
accountButton.pack()
def selectAccount():
print("nope")
#------------------------- Opening Text Box: Create / Choose Account
window = tkinter.Tk()
window.title("ATM - Inovated Online Banking")
window.geometry("400x100")
label = tkinter.Label(window, text="Thank you for using online Banking Canada. Howe can we help you?")
button = tkinter.Button(window, text="Create Account", command=createAccount)
button2 = tkinter.Button(window, text="Select Account", command=selectAccount)
label.pack()
button.pack()
button2.pack()
看这行: number = userAnswer.get()
这在createAccount
函数中是本地的。 您可以重新构造,将其作为参数传递或以其他各种方式传递。
另外,您永远不应有两个tk.Tk()
实例。 因此,您应该进行重组。 如果您确实想要一个新窗口,则可以使用tk.Toplevel
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.