CODE :
import tkinter as tk
from tkinter import messagebox
# Dummy data for ATM user
USER_PIN = "1234"
balance = 1000.0
# Functions
def verify_pin():
entered_pin = pin_entry.get()
if entered_pin == USER_PIN:
login_window.destroy()
open_main_menu()
else:
messagebox.showerror("Error", "Incorrect PIN")
def open_main_menu():
global menu_window
menu_window = tk.Toplevel()
menu_window.title("ATM Main Menu")
menu_window.geometry("300x300")
tk.Label(menu_window, text="Welcome to R2C ATM", font=('Arial', 14)).pack(pady=10)
tk.Button(menu_window, text="Check Balance", width=20, command=check_balance).pack(pady=5)
tk.Button(menu_window, text="Deposit", width=20, command=deposit_money).pack(pady=5)
tk.Button(menu_window, text="Withdraw", width=20, command=withdraw_money).pack(pady=5)
tk.Button(menu_window, text="Exit", width=20, command=menu_window.destroy).pack(pady=5)
def check_balance():
messagebox.showinfo("Balance", f"Your current balance is ₹{balance:.2f}")
def deposit_money():
def perform_deposit():
global balance
try:
amount = float(deposit_entry.get())
if amount <= 0:
raise ValueError
balance += amount
messagebox.showinfo("Success", f"Deposited ₹{amount:.2f} successfully!")
deposit_win.destroy()
except:
messagebox.showerror("Error", "Enter a valid amount")
deposit_win = tk.Toplevel(menu_window)
deposit_win.title("Deposit")
tk.Label(deposit_win, text="Enter amount to deposit:").pack(pady=5)
deposit_entry = tk.Entry(deposit_win)
deposit_entry.pack(pady=5)
tk.Button(deposit_win, text="Deposit", command=perform_deposit).pack(pady=5)
def withdraw_money():
def perform_withdraw():
global balance
try:
amount = float(withdraw_entry.get())
if amount <= 0 or amount > balance:
raise ValueError
balance -= amount
messagebox.showinfo("Success", f"Withdrew ₹{amount:.2f} successfully!")
withdraw_win.destroy()
except:
messagebox.showerror("Error", "Enter a valid amount within balance")
withdraw_win = tk.Toplevel(menu_window)
withdraw_win.title("Withdraw")
tk.Label(withdraw_win, text="Enter amount to withdraw:").pack(pady=5)
withdraw_entry = tk.Entry(withdraw_win)
withdraw_entry.pack(pady=5)
tk.Button(withdraw_win, text="Withdraw", command=perform_withdraw).pack(pady=5)
# Login Window
login_window = tk.Tk()
login_window.title("ATM Login")
login_window.geometry("300x150")
tk.Label(login_window, text="Enter PIN:", font=('Arial', 12)).pack(pady=10)
pin_entry = tk.Entry(login_window, show="*", font=('Arial', 12))
pin_entry.pack()
tk.Button(login_window, text="Login", command=verify_pin).pack(pady=10)
login_window.mainloop()
OUTPUT :
LOGIN PAGE :
MAIN MENU :
CHECK BALANCE :
AMOUNT DEPOSIT :
AFTER DEPOSITION :