我编写了一个代码来模拟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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句