Ai Mini
Ai Mini
Aim:
To implement Banking system using Tkinter module in python.
Algorithm:
1. Initialize: Set password and initial balance.
2. Verify Password: Ask for password; return True if correct, else show error.
3. Check Balance: Verify password; if correct, display balance.
4. Deposit:
o Verify password.
o If correct, check if amount is positive; update balance or show error.
5. Withdraw:
o Verify password.
o If correct, check if amount is valid and ≤ balance; update balance or show error.
Source code:
import tkinter as tk
from tkinter import simpledialog, messagebox
class BankSystem:
def __init__(self, password, initial_balance=0):
self.password = password
self.balance = initial_balance
def verify_password(self):
user_password = simpledialog.askstring("Password", "Enter your password:", show='*')
if user_password == self.password:
return True
else:
messagebox.showerror("Error", "Incorrect password!")
return False
def check_balance(self):
if self.verify_password():
messagebox.showinfo("Balance", f"Your current balance is: ${self.balance}")
class BankApp:
def __init__(self, root):
self.bank = BankSystem(password="1234", initial_balance=1000)
self.root = root
self.root.title("Banking System")
# Balance button
self.check_balance_btn = tk.Button(root, text="Check Balance", command=self.check_balance,
width=20, height=2)
self.check_balance_btn.pack(pady=10)
# Deposit button
self.deposit_btn = tk.Button(root, text="Deposit", command=self.deposit, width=20, height=2)
self.deposit_btn.pack(pady=10)
# Withdraw button
self.withdraw_btn = tk.Button(root, text="Withdraw", command=self.withdraw, width=20, height=2)
self.withdraw_btn.pack(pady=10)
# Exit button
self.exit_btn = tk.Button(root, text="Exit", command=root.quit, width=20, height=2)
self.exit_btn.pack(pady=10)
def check_balance(self):
self.bank.check_balance()
def deposit(self):
try:
amount = float(simpledialog.askstring("Deposit", "Enter amount to deposit:"))
self.bank.deposit(amount)
except ValueError:
messagebox.showerror("Error", "Invalid amount!")
def withdraw(self):
try:
amount = float(simpledialog.askstring("Withdraw", "Enter amount to withdraw:"))
self.bank.withdraw(amount)
except ValueError:
messagebox.showerror("Error", "Invalid amount!")
if __name__ == "__main__":
root = tk.Tk()
app = BankApp(root)
root.mainloop()
Output:
Inference:
This simple banking application provides a basic framework for managing user accounts with functionalities
for checking balances, depositing, and withdrawing funds, all while ensuring secure access through
password verification.
Result:
Thus, the above program was executed successfully and the output is verified