Python,tkinter弹出窗口错误

2024-05-29 10:29:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我做了一个代码来模拟ATM接口,但是第二阶段似乎有一个错误。 步骤1:要求创建/选择银行帐户 第二步:选择“create”,进入defcreate account:打开 步骤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()

Tags: textnumbertkinterdef错误buttonaccountwindow
1条回答
网友
1楼 · 发布于 2024-05-29 10:29:01

看这行:number = userAnswer.get()

这是createAccount函数的局部函数。你可以重新构造,把它作为一个论点,或者其他各种方式。你知道吗

另外,您不应该有两个tk.Tk()实例。所以,你应该重组。如果你真的想要一个新窗口,你可以使用tk.Toplevel

相关问题 更多 >

    热门问题