9. 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()
class Account: def __init__(self, username, balance): self.username = username self.balance = balance
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.
Bank.withdraw(self, accountNumber, amount):
methodtransactionLog = []
for Bank, that records all activity for all its customerstransactionLog = []
for Account, that records specific activity for that specific account