Answer To: ITECH1400 – Foundations of Programming School of Science, Engineering and Information Technology...
Amit answered on Sep 11 2020
33533/bankaccount.pyfrom tkinter import messagebox
class BankAccount:
account_number = '0'
pin_number = ''
balance = 0.0
interest_rate = 0.0
amount_entry = 0.0
transaction = ""
transaction_list = []
def __init__(self):
account_number = '0'
pin_number = ''
balance = 0.0
interest_rate = 0.0
transaction_list = []
def deposit_funds(self, amount):
try:
temp_amount = float(amount)
except:
raise Exception("Alert", "Please enter a valid amount")
if temp_amount < 0:
raise Exception("Alert", "Bad Amount")
return BankAccount.balance + float(amount)
def withdraw_funds(self, amount):
try:
temp_amount = float(amount)
except:
raise Exception("Alert", "Please enter a valid amount")
if temp_amount < 0:
raise Exception("Alert", "Bad Amount")
if temp_amount > BankAccount.balance:
raise Exception("Alert", "Bad Amount")
return BankAccount.balance - float(amount)
def get_transaction_string(self):
tup = (BankAccount.transaction , BankAccount.amount_entry)
BankAccount.transaction_list.append(tup)
return BankAccount.transaction_list
def save_to_file(self):
file = open(str(BankAccount.account_number) +'.txt',"w")
file.write(BankAccount.account_number + '\n')
file.write(BankAccount.pin_number + '\n')
file.write(str(BankAccount.balance) + '\n')
file.write(str(BankAccount.interest_rate) + '\n')
for a in BankAccount.transaction_list:
file.write(str(a[0]) + '\n')
file.write(str(a[1]) + '\n')
file.close()
33533/main.pyimport tkinter as tk
from tkinter import messagebox
from pylab import plot, show, xlabel, ylabel
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from bankaccount import BankAccount
win = tk.Tk()
win.geometry('440x640')
win.title('FedUni Banking')
account_number_var = tk.StringVar()
account_number_entry = tk.Entry(win, textvariable=account_number_var)
account_number_entry.focus_set()
pin_number_var = tk.StringVar()
account_pin_entry = tk.Entry(win, text='PIN Number', textvariable=pin_number_var)
account_pin_entry.config(show="*")
balance_var = tk.StringVar()
balance_var.set('Balance: $0.00')
balance_label = tk.Label(win, textvariable=balance_var)
amount_entry = tk.Entry(win)
transaction_text_widget = tk.Text(win, height=10, width=48)
bankAccount = BankAccount()
# Login Screen
def clear_pin_entry():
account_pin_entry.delete(0, tk.END)
account_pin_entry.insert(0, "")
def handle_pin_button(event):
if account_pin_entry.get() == "":
account_pin_entry.delete(0, tk.END)
account_pin_entry.insert(0, str(event))
else:
pin = int(account_pin_entry.get())
pin = pin * 10 + event
account_pin_entry.delete(0, tk.END)
account_pin_entry.insert(0, str(pin))
def log_in():
global account
global pin_number_entry
global account_num_entry
global balance_var
global interest_rate
BankAccount.pin_number = account_pin_entry.get()
file = account_number_var.get()
file = file + ".txt"
try:
fileP=open(file, "r")
lines = fileP.readlines()
account_num_entry = account_number_var.get()
if BankAccount.pin_number == lines[1].rstrip():
BankAccount.account_number = account_num_entry
BankAccount.balance = float(lines[2].rstrip())
BankAccount.interest_rate = float(lines[3].rstrip())
i = 0
j = 0
for line in lines:
tup = ()
if i > 3 :
div = j % 2
if div == 0:
var1 = line.rstrip()
j = j + 1
else:
var2 = line.rstrip()
tup = (var1 , var2)
BankAccount.transaction_list.append(tup)
j = j + 1
i = i + 1
remove_all_widgets()
create_account_screen()
fileP.close()
else:
messagebox.showinfo("Alert", "Bad Pin Number")
account_pin_entry.delete(0,...