Create a banking system that captures the following details:
1. Customer Name
2. Bank Name
3. Branch
4. Current Balance
Add the following buttons
First Customer, Second Customer, Third Customer, Reset, Exit.
Using “Hungarian” name the following textbox controls as follows:
Text Boxes
txtCustomerName, txtBankName, txtBranchName, txtCurrentBalance
Using “Hungarian” name the following button controls as follows:
Buttons
btnFirstCustomer, btnSecondCustomer, btnThirdCustomer, btnReset, btnExit
import tkinter as tk
from tkinter import messagebox
class BankingSystem:
def __init__(self, master):
self.master = master
master.title("Banking System")
# Labels
tk.Label(master, text="Customer Name:").grid(row=0, column=0, padx=10, pady=5)
tk.Label(master, text="Bank Name:").grid(row=1, column=0, padx=10, pady=5)
tk.Label(master, text="Branch:").grid(row=2, column=0, padx=10, pady=5)
tk.Label(master, text="Current Balance:").grid(row=3, column=0, padx=10, pady=5)
# Text Boxes (Hungarian Naming Convention)
self.txtCustomerName = tk.Entry(master)
self.txtCustomerName.grid(row=0, column=1, padx=10, pady=5)
self.txtBankName = tk.Entry(master)
self.txtBankName.grid(row=1, column=1, padx=10, pady=5)
self.txtBranchName = tk.Entry(master)
self.txtBranchName.grid(row=2, column=1, padx=10, pady=5)
self.txtCurrentBalance = tk.Entry(master)
self.txtCurrentBalance.grid(row=3, column=1, padx=10, pady=5)
# Buttons (Hungarian Naming Convention)
self.btnFirstCustomer = tk.Button(master, text="First Customer",
command=self.load_first_customer)
self.btnFirstCustomer.grid(row=4, column=0, padx=10, pady=5)
self.btnSecondCustomer = tk.Button(master, text="Second Customer",
command=self.load_second_customer)
self.btnSecondCustomer.grid(row=4, column=1, padx=10, pady=5)
self.btnThirdCustomer = tk.Button(master, text="Third Customer",
command=self.load_third_customer)
self.btnThirdCustomer.grid(row=5, column=0, padx=10, pady=5)
self.btnReset = tk.Button(master, text="Reset", command=self.reset_fields)
self.btnReset.grid(row=5, column=1, padx=10, pady=5)
self.btnExit = tk.Button(master, text="Exit", command=master.quit)
self.btnExit.grid(row=6, column=0, columnspan=2, padx=10, pady=10)
def load_first_customer(self):
self.clear_fields()
self.txtCustomerName.insert(0, "Joy Mwangi")
self.txtBankName.insert(0, "National Bank")
self.txtBranchName.insert(0, "Main Branch")
self.txtCurrentBalance.insert(0, "Ksh15000")
def load_second_customer(self):
self.clear_fields()
self.txtCustomerName.insert(0, "Julian Omondi")
self.txtBankName.insert(0, "City Bank")
self.txtBranchName.insert(0, "Downtown")
self.txtCurrentBalance.insert(0, "Ksh23000")
def load_third_customer(self):
self.clear_fields()
self.txtCustomerName.insert(0, "Caroline Chebet")
self.txtBankName.insert(0, "Global Bank")
self.txtBranchName.insert(0, "Uptown")
self.txtCurrentBalance.insert(0, "Ksh35000")
def clear_fields(self):
self.txtCustomerName.delete(0, tk.END)
self.txtBankName.delete(0, tk.END)
self.txtBranchName.delete(0, tk.END)
self.txtCurrentBalance.delete(0, tk.END)
def reset_fields(self):
self.clear_fields()
if __name__ == "__main__":
root = tk.Tk()
banking_system = BankingSystem(root)
root.mainloop()
Required
i. Design a well labeled form
ii. Write a simple code on all the buttons that will display the first, second and third
customer.
iii. Write a simple code that will reset/clear the records on each textbox.
iv. Write a simple code that will exit the form.
Title.
-------------------------------
| Banking System |
-------------------------------
Input fields
Customer Name: [ txtCustomerName ]
Bank Name: [ txtBankName ]
Branch: [ txtBranchName ]
Current Balance: [ txtCurrentBalance ]
Buttons
[ btnFirstCustomer ] [ btnSecondCustomer ]
[ btnThirdCustomer ] [ btnReset ]
[ btnExit ]