External Exam Download Resources Web Applications Games Recycle Bin

Auto teller

auto teller.py

from Bank import *
from tkinter import *

class ATM():
    def __init__(self):
        self.bank = Bank()
        self.window = Tk()
        self.widgets()
        self.bindings()
        self.pack()
        self.window.mainloop()

    #-----TKINTER:
    def widgets(self):
        self.window.btnCreateUser = Button(text="Create User")
        self.window.btnDeposit = Button(text="Deposit")
        self.window.btnDisplayAccount = Button(text="Display Account")
        self.window.lblFeedback = Label()

    def bindings(self):
        self.window.btnCreateUser.bind("<ButtonPress>", self.createUser)
        self.window.btnDeposit.bind("<ButtonPress>", self.deposit)
        self.window.btnDisplayAccount.bind("<ButtonPress>", self.displayAccount)

    def pack(self):
        self.window.btnCreateUser.pack()
        self.window.btnDeposit.pack()
        self.window.btnDisplayAccount.pack()
        self.window.lblFeedback.pack()

    #-----ATM:
    def deposit(self, event):
        self.bank.deposit(0, 99)

    def createUser(self, event):
        self.bank.createUser("Ricky", 50)

    def displayAccount(self, event):
        feedback = self.bank.displayAccount(0)
        self.window.lblFeedback.configure(text=feedback)

cash_r_us = ATM()

Account.py

class Account:
    def __init__(self, username, balance):
        self.username = username
        self.balance = balance

Bank.py

from Account import *
class Bank:
    def __init__(self):
        self.accounts = {}
        self.accountNumber = 0 #unique number for every account
    
    def displayAccount(self, accountNumber):
        return("Account number: " + str(accountNumber) + "\n" +
                "Username: " + str(self.accounts[accountNumber].username) + "\n" +
                "Balance: $" + str(self.accounts[accountNumber].balance) + "\n")

    #set balance default to $0 if it is not assigned a value when called:
    def createUser(self, username, balance = 0):
        #uses Account class, which acts as a "template" or blueprint for the account:
        newAccount = Account(username, balance)
    
        # store account in dictionary, using unique account number as key:
        self.accounts[self.accountNumber] = newAccount
        self.accountNumber += 1
        # ^^ increment so the account number stays unique on creation
    
    def deposit(self, accountNumber, amount):
        self.accounts[accountNumber].balance += amount

Note - all files must be saved in the same folder location for this program to work.


The below activities have been taken from the OOP - Autoteller Console activity (console Python). It is strongly suggested that before you attempt the below, develop the tk interface (e.g. entry fields, list boxes, etc.) to allow different accounts to be created / manipulated.


  1. create Bank.withdraw(self, accountNumber, amount): method
  2. prevent the withdraw method from withdrawing more money than i have in my account (so i should not be able to go into a negative balance).
  3. both deposit and withdraw methods should give me a receipt or balance.
  4. display all accounts in Bank class dictionary (sorted)
  5. add password to Account class
  6. add account protection to withdraw method (above) so that withdrawal cannot be completed without correctly supplied account password
  7. transactionLog = [] for Bank, that records all activity for all its customers
  8. transactionLog = [] for Account, that records specific activity for that specific account
  9. when the user is created, their account number should be displayed to the screen. otherwise, they won't know which account number to deposit / withdraw from. please fix this.
  10. could we substitute a unique email address for a unique account number? if so, can you enable the accounts dictionary to check if the key (email) exists, and if not, it can add it as a new account.. otherwise return an error message.
  11. user proof the above code using exception handling.