12 – Real-World Python Projects – Expense Tracker with GUI

๐ŸŽฏ Project Objective

To build a Graphical Expense Tracker using Python that allows users to add, view, and analyze expenses with a user-friendly GUI.
Skills Demonstrated:

  • GUI development using Tkinter
  • File handling and data storage (CSV or JSON)
  • Data analysis and visualization
  • Event handling and user input validation

Project: Expense Tracker with GUI

Project Description

The Expense Tracker app allows users to:

  • Add new expenses with category, amount, and description
  • View expense history
  • Visualize expenses with charts
  • Save and load data for persistence

Use Cases:

  • Personal finance management
  • Small business expense tracking
  • Monthly budget analysis

Python Example Code โ€“ Basic GUI Version

import tkinter as tk
from tkinter import messagebox
import pandas as pd
import os
import matplotlib.pyplot as plt

# File to store expenses
file_name = "expenses.csv"

# Load existing data
if os.path.exists(file_name):
    df = pd.read_csv(file_name)
else:
    df = pd.DataFrame(columns=["Date", "Category", "Amount", "Description"])

# Function to add expense
def add_expense():
    global df
    date = entry_date.get()
    category = entry_category.get()
    amount = entry_amount.get()
    description = entry_desc.get()

    if not date or not category or not amount:
        messagebox.showerror("Error", "Please fill all required fields")
        return

    try:
        amount = float(amount)
    except ValueError:
        messagebox.showerror("Error", "Amount must be a number")
        return

    df = pd.concat([df, pd.DataFrame({"Date":[date], "Category":[category], "Amount":[amount], "Description":[description]})], ignore_index=True)
    df.to_csv(file_name, index=False)
    messagebox.showinfo("Success", "Expense added successfully!")
    entry_date.delete(0, tk.END)
    entry_category.delete(0, tk.END)
    entry_amount.delete(0, tk.END)
    entry_desc.delete(0, tk.END)

# Function to view summary
def view_summary():
    if df.empty:
        messagebox.showinfo("Summary", "No expenses recorded yet!")
        return
    summary = df.groupby("Category")["Amount"].sum()
    messagebox.showinfo("Expense Summary", str(summary))
    # Plot pie chart
    summary.plot(kind="pie", autopct="%1.1f%%", title="Expenses by Category")
    plt.show()

# GUI setup
root = tk.Tk()
root.title("Expense Tracker")

# Labels and Entries
tk.Label(root, text="Date (YYYY-MM-DD)").grid(row=0, column=0)
tk.Label(root, text="Category").grid(row=1, column=0)
tk.Label(root, text="Amount").grid(row=2, column=0)
tk.Label(root, text="Description").grid(row=3, column=0)

entry_date = tk.Entry(root)
entry_category = tk.Entry(root)
entry_amount = tk.Entry(root)
entry_desc = tk.Entry(root)

entry_date.grid(row=0, column=1)
entry_category.grid(row=1, column=1)
entry_amount.grid(row=2, column=1)
entry_desc.grid(row=3, column=1)

# Buttons
tk.Button(root, text="Add Expense", command=add_expense).grid(row=4, column=0, pady=10)
tk.Button(root, text="View Summary", command=view_summary).grid(row=4, column=1, pady=10)

root.mainloop()

โœ… Output:

  • GUI window for adding expenses
  • Validation for required fields and numeric amount
  • Expense summary and pie chart visualization

โœ… Key Features

  • GUI for easy interaction
  • Add, view, and summarize expenses
  • Save and load data for persistence
  • Visualize expenses with pie charts
  • Basic input validation and error handling

Learning Points

Building real-world practical applications in Python

Tkinter GUI development

File handling using pandas

Data analysis and visualization

Event-driven programming


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *