What is it ?
The Expense Tracker
is a cool Python program I built to help keep track of all the money stuff, like where it’s going and what it’s being spent on. It uses tkinter
for the user interface, tkcalendar
for picking dates, and csv
for saving the data. It’s like having a digital notebook where you can log your expenses and see how much you’ve spent.
Why did I make one
The main reason for creating the Expense Tracker is to help people, especially students like me, keep track of their spending in an easy and organised way. Managing money can be tough, and it’s easy to lose track of where your money goes. This app aims to solve that problem by providing a simple tool to log and monitor expenses.
Features
- Easy-to-Use Interface:
- Built with
tkinter
andtkcalendar
. - Simple and clean design with fields for date, category, amount, and description.
- Built with
- Data Storage:
- Saves expenses in a CSV file (
expenses.csv
). - Loads expenses from the CSV file when you start the app.
- Saves expenses in a CSV file (
- Expense Management:
- Add new expenses.
- Edit existing expenses.
- Delete expenses you don’t need anymore.
- Filtering and Summarizing:
- Filter expenses by category to see specific types of expenses.
- Generate summary reports showing totals for each category.
How it works
Setting Up:
The ExpenseTracker
class sets up the main window and loads any existing expenses from the CSV file when you start it.
def __init__(self, root, filename='expenses.csv'):
self.root = root
self.root.title("Expense Tracker")
self.filename = filename
self.load_expenses()
self.create_gui()
Loading and Saving Data:
- The app reads from a CSV file to load expenses.
- Whenever you add, edit, or delete an expense, it saves the changes back to the CSV file.
def load_expenses(self):
try:
with open(self.filename, mode='r', newline='') as file:
reader = csv.reader(file)
self.expenses = [row for row in reader]
except FileNotFoundError:
self.expenses = []
def save_expenses(self):
with open(self.filename, mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerows(self.expenses)
Adding, Editing, and Deleting Expenses:
- You can add new expenses by entering the date, category, amount, and description.
- Edit existing expenses if you need to change something.
- Delete expenses you don’t need anymore.
def add_expense(self, date, category, amount, description=''):
self.expenses.append([date, category, amount, description])
self.save_expenses()
self.update_expense_list()
def edit_expense(self, index, date, category, amount, description):
self.expenses[index] = [date, category, amount, description]
self.save_expenses()
self.update_expense_list()
def delete_expense(self, index):
del self.expenses[index]
self.save_expenses()
self.update_expense_list()
Filtering and Summary:
- You can filter expenses by category to see only the ones you’re interested in.
- Get a summary report to see how much you’ve spent in each category.
def apply_filter(self):
category = self.filter_category_combobox.get()
if category == "All":
self.update_expense_list()
else:
filtered_expenses = [exp for exp in self.expenses if exp[1] == category]
self.update_expense_list(filtered_expenses)
def show_summary(self):
summary = {}
for expense in self.expenses:
category = expense[1]
amount = float(expense[2])
if category in summary:
summary[category] += amount
else:
summary[category] = amount
summary_message = "\n".join([f"{category}: {total:.2f}" for category, total in summary.items()])
messagebox.showinfo("Summary Report", summary_message)
User Interface
- Main Frame: The main area where everything is displayed.
- Date Entry: A calendar widget to pick the date of the expense.
- Category Combobox: A dropdown to select the expense category.
- Amount Entry: Input field for the expense amount.
- Description Entry: Input field for an optional description.
- Expense List: A list showing all your recorded expenses.
- Buttons: Buttons to add, edit, delete, filter, and get a summary of expenses.