0

I made a code to simulate an ATM interface, however the 2nd phase seems to have a bug. Step1: Ask to create/choose a bank Account Step2: Pick "create" it goes to def create account: which opens Step3: Enter account number: error(Variable used seems to be undefined?) I dont see the problem, maybe Im blind but i dont see what could be causing the error. Why is my variable: userAnswer always come back undefined.

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()

1 Answer 1

1

Look at this line: number = userAnswer.get()

This is local to the createAccount function. You could re-structure, pass it in as an argument, or various other ways.

Also you should never have two instances of tk.Tk(). So, you should restructure. If you really want a new window you could just use tk.Toplevel

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.