Loan Management System - EMI Calculator

PROGRAM:

import tkinter as tk

from tkinter import messagebox

from reportlab.lib.pagesizes import A4

from reportlab.pdfgen import canvas


def calculate_loan():

    try:

        principal = float(entry_principal.get())

        rate = float(entry_rate.get()) / 100 / 12  

        years = int(entry_years.get())

        months = years * 12


        emi = (principal * rate * (1 + rate) ** months) / ((1 + rate) ** months - 1)

        total_payment = emi * months

        total_interest = total_payment - principal


        result.set(f"EMI: ₹{emi:.2f}\nTotal Payment: ₹{total_payment:.2f}\nInterest: ₹{total_interest:.2f}")

        global statement_data

        statement_data = {

            "Principal": principal,

            "Rate": rate * 12 * 100,

            "Years": years,

            "EMI": emi,

            "Total Payment": total_payment,

            "Interest": total_interest

        }


    except ValueError:

        messagebox.showerror("Input Error", "Please enter valid numeric values.")


def save_pdf():

    if not statement_data:

        messagebox.showerror("Error", "No data to save. Calculate first.")

        return

    

    filename = "Loan_Statement.pdf"

    c = canvas.Canvas(filename, pagesize=A4)

    width, height = A4


    c.setFont("Helvetica-Bold", 20)

    c.drawString(200, height - 50, "Loan Statement")


    c.setFont("Helvetica", 12)

    y = height - 100

    for key, value in statement_data.items():

        c.drawString(100, y, f"{key}: ₹{value:.2f}" if isinstance(value, float) else f"{key}: {value}")

        y -= 20


    c.save()

    messagebox.showinfo("Success", f"PDF saved as {filename}")


root = tk.Tk()

root.title("Loan Management System")

root.geometry("400x400")


statement_data = {}


tk.Label(root, text="Loan Amount (₹):").pack()

entry_principal = tk.Entry(root)

entry_principal.pack()


tk.Label(root, text="Annual Interest Rate (%):").pack()

entry_rate = tk.Entry(root)

entry_rate.pack()


tk.Label(root, text="Loan Term (Years):").pack()

entry_years = tk.Entry(root)

entry_years.pack()


tk.Button(root, text="Calculate Loan", command=calculate_loan).pack(pady=10)

result = tk.StringVar()

tk.Label(root, textvariable=result, justify="left").pack()


tk.Button(root, text="Download PDF Statement", command=save_pdf).pack(pady=10)


root.mainloop()

 

OUTPUT:



Comments

Popular posts from this blog

Bus Booking Application using Tkinter (Python GUI)

ATM Simulation using Python and Tkinter GUI

Healthcare Chatbot Using Tkinter GUI in Python