forked from ndleah/python-mini-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103) | ||
[![View My Profile](https://img.shields.io/badge/View-My_Profile-green?logo=GitHub)](https://github.com/otahina) | ||
|
||
# Script Title | ||
<!--Remove the below lines and add yours --> | ||
A short description about the script must be mentioned here. | ||
|
||
### Prerequisites | ||
<!--Remove the below lines and add yours --> | ||
Modules required to be able to use the script successfully | ||
and how to install them. | ||
(Including a `requirements.txt` file will work.) | ||
|
||
### How to run the script | ||
<!--Remove the below lines and add yours --> | ||
Steps on how to run the script along with suitable examples. | ||
|
||
### Screenshot/GIF showing the sample use of the script | ||
<!--Remove the below lines and add yours --> | ||
Add a jpeg/png/gif file here. | ||
|
||
## *Author Name* | ||
<!--Remove the below lines and add yours --> | ||
The name of the author of the code goes here. | ||
If you have a web site or a Git user name, feel free to link. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import tkinter as tk | ||
from tkinter import messagebox | ||
from matplotlib.figure import Figure | ||
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg | ||
import matplotlib.pyplot as plt | ||
|
||
class Application(tk.Tk): | ||
def __init__(self): | ||
super().__init__() | ||
self.title("Finance Tracker") | ||
|
||
self.income = 0 | ||
self.expense = 0 | ||
|
||
# Income Entry | ||
tk.Label(self, text="Income: ").grid(row=0, column=0) | ||
self.income_entry = tk.Entry(self) | ||
self.income_entry.grid(row=0, column=1) | ||
|
||
# Expense Entry | ||
tk.Label(self, text="Expense: ").grid(row=1, column=0) | ||
self.expense_entry = tk.Entry(self) | ||
self.expense_entry.grid(row=1, column=1) | ||
|
||
# Buttons | ||
tk.Button(self, text="Add Income", command=self.add_income).grid(row=2, column=0) | ||
tk.Button(self, text="Add Expense", command=self.add_expense).grid(row=2, column=1) | ||
|
||
|
||
# Plot | ||
self.fig = Figure(figsize = (5, 5), dpi = 100) | ||
self.canvas = FigureCanvasTkAgg(self.fig, master = self) | ||
self.canvas.draw() | ||
self.canvas.get_tk_widget().grid(row=3, column=0, columnspan=2) | ||
|
||
|
||
def add_income(self): | ||
try: | ||
amount = float(self.income_entry.get()) | ||
self.income += amount | ||
self.update_plot() | ||
self.income_entry.delete(0, 'end') | ||
except ValueError: | ||
messagebox.showerror("Invalid Input", "Please enter a valid number for income") | ||
|
||
|
||
def add_expense(self): | ||
try: | ||
amount = float(self.expense_entry.get()) | ||
self.expense += amount | ||
self.update_plot() | ||
self.expense_entry.delete(0, 'end') | ||
except ValueError: | ||
messagebox.showerror("Invalid Input", "Please enter a valid number for expense") | ||
|
||
def update_plot(self): | ||
self.fig.clear() | ||
plt.figure(self.fig.number) | ||
plt.pie([self.income, self.expense], labels=['Income', 'Expense'], autopct='%1.1f%%') | ||
self.canvas.draw() | ||
|
||
if __name__ == "__main__": | ||
app = Application() | ||
app.mainloop() | ||
|