Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk # python 3
- from tkinter import font as tkfont # python 3
- from tkinter import messagebox
- from tkinter import *
- from bank_system import *
- from globalfunc import *
- from customer import Customer
- from admin import Admin
- from account import Account
- #import tkFont as tkfont # python 2
- current_customer = None
- current_admin = None
- bank_system = BankSystem() #enables the program to refer to functions within the BankSystem class
- #------ Global Functions -------#
- def print_balance():
- tk.messagebox.showwarning(
- "New balance",
- "Your new balance is: %.2f ... Please login again to confirm adjustments to account" %current_customer.get_account().balance)
- class SampleApp(tk.Tk):
- def __init__(self, *args, **kwargs):
- tk.Tk.__init__(self, *args, **kwargs)
- self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")
- self.body_font = tkfont.Font(family='arial', size=14, weight='normal', slant='roman')
- # the container is where we'll stack a bunch of frames
- # on top of each other, then the one we want visible
- # will be raised above the others
- container = tk.Frame(self)
- container.pack(side="top", fill="both", expand=True)
- container.grid_rowconfigure(0, weight=1)
- container.grid_columnconfigure(0, weight=1)
- self.frames = {}
- for F in (StartPage, CustomerLogin, AdminMenu,AdminLogin, CustomerMenu , CustDepositMoney, CustWithdrawMoney,
- CustUpdateName, CustUpdateAdd, CustomerAccountOptions, AdminCustomerInformation, EditCustomerDetails,
- DeleteCustomer):
- page_name = F.__name__
- frame = F(parent=container, controller=self)
- self.frames[page_name] = frame
- # put all of the pages in the same location;
- # the one on the top of the stacking order
- # will be the one that is visible.
- frame.grid(row=0, column=0, sticky="nsew")
- self.show_frame("StartPage")
- def show_frame(self, page_name):
- '''Show a frame for the given page name'''
- frame = self.frames[page_name]
- frame.tkraise()
- return frame
- class StartPage(tk.Frame):
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- self.controller = controller
- label = tk.Label(self, text="Welcome to the Login Page", font=controller.title_font)
- label.pack(side="top", fill="x", pady=10)
- button1 = tk.Button(self, text="Go to Customer login",
- command=lambda: controller.show_frame("CustomerLogin"))
- button2 = tk.Button(self, text="Go to Admin login",
- command=lambda: controller.show_frame("AdminLogin"))
- button1.pack()
- button2.pack()
- class CustomerLogin(tk.Frame):
- def __init__(self, parent, controller,):
- bank_system.customers_list = []
- bank_system.admins_list = []
- bank_system.load_bank_data()
- global usernameentry
- global passwordentry
- tk.Frame.__init__(self, parent,)
- self.controller = controller
- label = tk.Label(self, text="Customer Login", font=controller.title_font)
- label.pack(side="top", fill="x", pady=10)
- label2 = tk.Label(self, text="Enter Username:")
- label2.pack(side="top", fill="x", pady=3)
- usernameentry = tk.Entry(self,)
- usernameentry.pack(side="top", expand=50)
- label3 = tk.Label(self, text="Enter Password:")
- label3.pack(side="top", fill="x", pady=3)
- passwordentry = tk.Entry(self, show="*")
- passwordentry.pack(side="top", expand=50)
- LoginButton = tk.Button(self, text="Login",
- command=self.CustomerLogin)
- LoginButton.pack(side="top", expand=50)
- button = tk.Button(self, text="Go to the start page",
- command=lambda: controller.show_frame("StartPage"),).pack(side="right",)
- #def passwordentry_delete(self):
- # passwordentry.delete(first=20,last=22)
- def CustomerLogin(self):
- name = str(usernameentry.get())
- password = str(passwordentry.get())
- found_customer = bank_system.search_customers_by_name(name)
- if found_customer == None:
- tk.messagebox.showwarning(
- "ERROR!",
- "Customer not found! - Please Try Again!")
- else:
- if (found_customer.check_password(password) == True):
- print('Customer found - Running customer page')
- frame = self.controller.show_frame("CustomerMenu")
- global current_customer
- current_customer = found_customer
- frame.refresh()
- else:
- tk.messagebox.showwarning(
- "ERROR!",
- "Incorrect Password - Please Try Again!")
- class CustomerMenu(tk.Frame):
- global nameprint
- def __init__(self, parent, controller):
- global bal
- global getname
- tk.Frame.__init__(self, parent)
- self.controller = controller
- label = tk.Label(self, text="Customer Menu", font=controller.title_font)
- label.pack(side="top", fill="x",)
- depositbutton = tk.Button(self, text="Deposit Money", command=lambda: controller.show_frame("CustDepositMoney"))
- depositbutton.pack()
- withdrawbutton = tk.Button(self, text="Withdraw Money", command=lambda: controller.show_frame("CustWithdrawMoney"))
- withdrawbutton.pack()
- label2 = tk.Label(self, text="Current Account Balance:", font=controller.body_font)
- label2.pack(side="top",)
- self.bal = tk.StringVar()
- label3 = tk.Label(self, textvariable=self.bal,)
- label3.pack(side="top",)
- profilelabel = tk.Label(self, text="Customer information:", font=controller.title_font)
- profilelabel.pack(side="top")
- labelnameprint = tk.Label(self, text="Customer Name:", font=controller.body_font)
- labelnameprint.pack(side="top",)
- self.nameprint = tk.StringVar()
- namelabel = tk.Label(self, textvariable=self.nameprint,)
- namelabel.pack(side="top",)
- labeladdressprint = tk.Label(self, text="Customer Address:", font=controller.body_font)
- labeladdressprint.pack(side="top",)
- self.addressprint = tk.StringVar()
- addresslabel = tk.Label(self, textvariable=self.addressprint,)
- addresslabel.pack(side="top",)
- updatename = tk.Button(self, text="Update name", command=lambda: controller.show_frame("CustUpdateName"))
- updatename.pack()
- updateaddress = tk.Button(self, text="Update address", command=lambda: controller.show_frame("CustUpdateAdd"))
- updateaddress.pack()
- returnbutton = tk.Button(self, text="Back",
- command=lambda: controller.show_frame("StartPage"))
- returnbutton.pack(side="left")
- def refresh(self):
- self.bal.set("Balance: £%.2f" % current_customer.get_account().balance)
- self.nameprint.set(current_customer.get_name())
- addr = ""
- for a in current_customer.get_address():
- addr += "%s\n" % a
- self.addressprint.set(addr)
- class CustDepositMoney(tk.Frame):
- def __init__(self, parent, controller):
- global depositentry
- global deposit
- tk.Frame.__init__(self, parent)
- self.controller = controller
- label = tk.Label(self, text="Deposit Money", font=controller.title_font)
- label.pack(side="top", fill="x",)
- label2 = tk.Label(self, text="Enter Amount:", font=controller.body_font)
- label2.pack(side="top", fill="x",)
- depositentry = tk.Entry(self,)
- depositentry.pack(side="top")
- submitbutton = tk.Button(self, text="Submit Request",command=self.DepositFunc)
- submitbutton.pack(side="top")
- returnbutton = tk.Button(self, text="Back",
- command=lambda: controller.show_frame("StartPage"))
- returnbutton.pack(side="left")
- def DepositFunc(self,):
- global amount
- global deposit
- amount = float(depositentry.get())
- current_customer.get_account().deposit(amount)
- self.controller.show_frame("StartPage")
- print_balance()
- class CustWithdrawMoney(tk.Frame):
- def __init__(self, parent, controller):
- global withdrawentry
- tk.Frame.__init__(self, parent)
- self.controller = controller
- label = tk.Label(self, text="Withdraw Money", font=controller.title_font)
- label.pack(side="top", fill="x", )
- label2 = tk.Label(self, text="Enter Amount:", font=controller.body_font)
- label2.pack(side="top", fill="x", )
- withdrawentry = tk.Entry(self, )
- withdrawentry.pack(side="top")
- withdrawbutton = tk.Button(self, text="Submit Request", command=self.WithdrawFunc)
- withdrawbutton.pack(side="top")
- returnbutton = tk.Button(self, text="Back",
- command=lambda: controller.show_frame("StartPage"))
- returnbutton.pack(side="left")
- def WithdrawFunc(self,):
- global amount
- amount = float(withdrawentry.get())
- withdraw = current_customer.get_account().withdraw(amount)
- self.controller.show_frame("StartPage")
- print_balance()
- class CustUpdateName(tk.Frame):
- def __init__(self, parent, controller):
- global NameEntry
- tk.Frame.__init__(self, parent)
- self.controller = controller
- label = tk.Label(self, text="Update Name", font=controller.title_font)
- label.pack(side="top", fill="x", )
- label2 = tk.Label(self, text="Enter Name:", font=controller.body_font)
- label2.pack(side="top", fill="x", )
- NameEntry = tk.Entry(self, )
- NameEntry.pack(side="top")
- submitbutton = tk.Button(self, text="Submit", command=self.updatename)
- submitbutton.pack()
- returnbutton = tk.Button(self, text="Back",
- command=lambda: controller.show_frame("StartPage"))
- returnbutton.pack(side="left")
- def updatename(self):
- global name
- name = str(NameEntry.get())
- updatename = current_customer.update_name(name)
- tk.messagebox.showwarning(
- "Success!",
- "Name has been updated!")
- self.controller.show_frame("AdminMenu")
- class CustUpdateAdd(tk.Frame):
- def __init__(self, parent, controller):
- global AddrEntry
- global AddrEntry2
- global AddrEntry3
- global AddrEntry4
- tk.Frame.__init__(self, parent)
- self.controller = controller
- label = tk.Label(self, text="Update Address", font=controller.title_font)
- label.pack()
- label2 = tk.Label(self, text="Enter New Address:", font=controller.body_font)
- label2.pack()
- label3 = tk.Label(self, text="Enter House Name/Number:")
- label3.pack()
- AddrEntry = tk.Entry(self, )
- AddrEntry.pack()
- label4 = tk.Label(self, text="Enter Street Name:")
- label4.pack()
- AddrEntry2 = tk.Entry(self, )
- AddrEntry2.pack()
- label5 = tk.Label(self, text="Enter City:")
- label5.pack()
- AddrEntry3 = tk.Entry(self, )
- AddrEntry3.pack()
- label6 = tk.Label(self, text="Enter Postcode:")
- label6.pack()
- AddrEntry4 = tk.Entry(self, )
- AddrEntry4.pack()
- submitbutton = tk.Button(self, text="Submit", command=self.updateaddress)
- submitbutton.pack()
- returnbutton = tk.Button(self, text="Back",
- command=lambda: controller.show_frame("StartPage"))
- returnbutton.pack(side="left")
- def updateaddress(self):
- line1 = str(AddrEntry.get())
- line2 = str(AddrEntry2.get())
- line3 = str(AddrEntry3.get())
- line4 = str(AddrEntry4.get())
- current_customer.update_address(line1, line2, line3, line4)
- tk.messagebox.showwarning(
- "Success!",
- "Name has been updated!")
- self.controller.show_frame("AdminMenu")
- #################################################################################################
- ####################### BELOW CONTAINS THE ADMIN PART OF THE GUI #######################
- #################################################################################################
- class AdminLogin(tk.Frame):
- def __init__(self, parent, controller, ):
- bank_system.customers_list = []
- bank_system.admins_list = []
- bank_system.load_bank_data()
- global usernameentry
- global passwordentry
- tk.Frame.__init__(self, parent, )
- self.controller = controller
- label = tk.Label(self, text="Customer Login", font=controller.title_font)
- label.pack(side="top", fill="x", pady=10)
- label2 = tk.Label(self, text="Enter Username:")
- label2.pack(side="top", fill="x", pady=3)
- usernameentry = tk.Entry(self, )
- usernameentry.pack(side="top", expand=50)
- label3 = tk.Label(self, text="Enter Password:")
- label3.pack(side="top", fill="x", pady=3)
- passwordentry = tk.Entry(self, show="*")
- passwordentry.pack(side="top", expand=50)
- LoginButton = tk.Button(self, text="Login",
- command=self.AdminLoginPage)
- LoginButton.pack(side="top", expand=50)
- button = tk.Button(self, text="Go to the start page",
- command=lambda: controller.show_frame("StartPage"), ).pack(side="right", )
- def AdminLoginPage(self):
- name = str(usernameentry.get())
- password = str(passwordentry.get())
- found_admin = bank_system.search_admin_by_name(name)
- if found_admin == None:
- tk.messagebox.showwarning(
- "ERROR!",
- "Admin not found! - Please Try Again!")
- else:
- if (found_admin.check_password(password) == True):
- print('Admin found - Running admin menu')
- frame = self.controller.show_frame("AdminMenu")
- global current_admin
- current_admin = found_admin
- else:
- tk.messagebox.showwarning(
- "ERROR!",
- "Incorrect Password - Please Try Again!")
- class AdminMenu(tk.Frame):
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- self.controller = controller
- label = tk.Label(self, text="Admin Dashboard", font=controller.title_font)
- label.pack(side="top", fill="x", pady=10)
- label2 = tk.Label(self, text="Admin Options", font=controller.body_font)
- label2.pack(side="top", fill="x", pady=10)
- custaccopbutton = tk.Button(self, text= "Customer Account Options", command=lambda: controller.show_frame("CustomerAccountOptions"))
- custaccopbutton.pack()
- editcustomerdetailsbutton = tk.Button(self, text= "Edit Customer Details", command=lambda: controller.show_frame("EditCustomerDetails"))
- editcustomerdetailsbutton.pack()
- deletecustomer = tk.Button(self, text="Delete Customer", command=lambda: controller.show_frame("DeleteCustomer"))
- deletecustomer.pack()
- printcustdetails = tk.Button(self, text="Print All Customer Details", command=self.showcustinfo)
- printcustdetails.pack()
- def showcustinfo(self):
- PrintAllCustomers()
- class CustomerAccountOptions(tk.Frame):
- def __init__(self, parent, controller):
- global customerusernameadmin
- tk.Frame.__init__(self, parent)
- self.controller = controller
- label = tk.Label(self, text="Customer Account Options", font=controller.title_font)
- label.pack(side="top", fill="x", pady=10)
- customerusernameadmin = tk.Entry(self,)
- customerusernameadmin.pack()
- nextbutton = tk.Button(self, text="Next", command= self.AdminCustomerLogin)
- nextbutton.pack()
- def AdminCustomerLogin(self):
- name = str(customerusernameadmin.get())
- found_customer = bank_system.search_customers_by_name(name)
- if found_customer == None:
- tk.messagebox.showwarning(
- "ERROR!",
- "Customer not found! - Please Try Again!")
- else:
- print('Customer found - Running customer page')
- frame = self.controller.show_frame("CustomerMenu")
- global current_customer
- current_customer = found_customer
- frame.refresh()
- class EditCustomerDetails(tk.Frame):
- def __init__(self, parent, controller):
- global customerusernameadmin
- global AdminCustomerLogin
- global custnameentry
- tk.Frame.__init__(self, parent)
- self.controller = controller
- label2 = tk.Label(self, text="Edit Customer details", font=controller.title_font)
- label2.pack(side="top", fill="x", pady=10)
- label2 = tk.Label(self, text="Enter customers name:", font=controller.body_font)
- label2.pack(side="top", fill="x", pady=10)
- custnameentry = tk.Entry(self,)
- custnameentry.pack()
- nextbutton = tk.Button(self, text="Next", command= self.AdminCustomerLogindetails)
- nextbutton.pack()
- def AdminCustomerLogindetails(self):
- name = str(custnameentry.get())
- found_customer = bank_system.search_customers_by_name(name)
- if found_customer == None:
- tk.messagebox.showwarning(
- "ERROR!",
- "Customer not found! - Please Try Again!")
- else:
- print('Customer found - Running customer page')
- frame = self.controller.show_frame("AdminCustomerInformation")
- global current_customer
- current_customer = found_customer
- frame.refresh()
- class AdminCustomerInformation(tk.Frame):
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- self.controller = controller
- #self.draw()
- def draw(self):
- controller = self.controller
- profilelabel = tk.Label(self, text="Customer information:", font=controller.title_font)
- profilelabel.pack(side="top")
- labelname = tk.Label(self, text="Customer Name",font=controller.body_font)
- labelname.pack(side="top", )
- labelnameprint = tk.Label(self, text="%s" % current_customer.name,)
- labelnameprint.pack(side="top", )
- self.nameprint = tk.StringVar()
- namelabel = tk.Label(self, textvariable=self.nameprint, )
- namelabel.pack(side="top", )
- address = ""
- for a in current_customer.get_address():
- address += "%s\n" % a
- labeladdr = tk.Label(self, text="Customer Address:", font=controller.body_font)
- labeladdr.pack(side="top", )
- labeladdressprint = tk.Label(self, text="%s" % address, )
- labeladdressprint.pack(side="top", )
- self.addressprint = tk.StringVar()
- addresslabel = tk.Label(self, textvariable=self.addressprint, )
- addresslabel.pack(side="top", )
- updatename = tk.Button(self, text="Update name", command=lambda: controller.show_frame("CustUpdateName"))
- updatename.pack()
- updateaddress = tk.Button(self, text="Update address", command=lambda: controller.show_frame("CustUpdateAdd"))
- updateaddress.pack()
- def refresh(self):
- for child in self.winfo_children():
- child.destroy()
- self.draw()
- class DeleteCustomer(tk.Frame):
- def __init__(self, parent, controller):
- global deleteent
- tk.Frame.__init__(self, parent)
- self.controller = controller
- profilelabel = tk.Label(self, text="Delete Customer:", font=controller.title_font)
- profilelabel.pack(side="top")
- labelnameprint = tk.Label(self, text="Customer Name:", font=controller.body_font)
- labelnameprint.pack(side="top", )
- deleteent = tk.Entry(self,)
- deleteent.pack()
- deletebutt = tk.Button(self, text="Update name", command=self.AdminDeleteCustomer)
- deletebutt.pack()
- def AdminDeleteCustomer(self):
- global deleteent
- customer_name = str(deleteent.get())
- customer_account = bank_system.search_customers_by_name(customer_name)
- if customer_account != None:
- bank_system.customers_list.remove(customer_account)
- # else:
- #print("\nOnly administrators with full admin rights can remove a customer from the bank system!\n")
- tk.messagebox.showwarning(
- "Success!",
- "User has been deleted.")
- self.controller.show_frame("AdminMenu ")
- class PrintAllCustomers():
- def __init__(self):
- self.parent = tk.Toplevel()
- info = self.printcustfunc()
- text = tk.Label(self.parent,text=info)
- text.pack()
- def printcustfunc(self):
- output = ""
- for c in bank_system.customers_list:
- output += "%s" % c.print_details()
- output += "------------------------\n"
- return output
- if __name__ == "__main__":
- app = SampleApp()
- app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement