-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
207 lines (149 loc) · 7.56 KB
/
Copy pathgui.py
File metadata and controls
207 lines (149 loc) · 7.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import tkinter as tk
from tkinter import messagebox
from backend import Transaction
LARGE_FONT = ("Arial", 20)
MEDIUM_FONT = ("Arial", 16)
SMALL_FONT = ("Arial", 14)
CURRENCY = "\u00a3"
class createMenu:
SIZE = "500x400"
TITLE = "Expense Tracker"
def __init__(self, root, tracker):
self.tracker = tracker
self.root = root
self.root.geometry(self.SIZE)
self.root.title(self.TITLE)
frame = tk.Frame(self.root)
frame.pack(expand=True, anchor="center")
# --- Description Label ---
description = tk.Label(frame, text="Pick an option", font=LARGE_FONT)
# --- Add Transaction Button ---
add_transaction = tk.Button(frame, text="Add Transaction", font=SMALL_FONT, width=20, height=2, command=self.create_transaction_menu)
# --- View Balance Button ---
view_balance = tk.Button(frame, text="View Balance", font=SMALL_FONT, width=20, height=2, command=self.create_balance_menu)
# --- View Summary Button ---
view_summary = tk.Button(frame, text="View Summary", font=SMALL_FONT, width=20, height=2, command=self.create_summary_menu)
# --- Exit Menu button ---
exit_button = tk.Button(frame, text="Save & Exit", font=SMALL_FONT, width=20, height=2, command=self.save_and_exit)
description.pack()
add_transaction.pack(pady=10)
view_balance.pack(pady=10)
view_summary.pack(pady=10)
exit_button.pack(pady=20)
self.root.mainloop()
def create_transaction_menu(self):
root = tk.Toplevel(self.root)
createTransactionMenu(root, self.tracker)
def create_balance_menu(self):
root = tk.Toplevel(self.root)
createBalanceMenu(root, self.tracker)
def create_summary_menu(self):
multiplier = max(len(self.tracker.category_summary()) - 2, 0)
size_y = 300 + (multiplier * 50)
size = "500x" + str(size_y)
root = tk.Toplevel(self.root)
createSummaryMenu(root, size, self.tracker)
def save_and_exit(self):
self.tracker.save_to_file()
self.root.destroy()
class createTransactionMenu:
SIZE = "400x300"
TITLE = "Add Transaction"
def __init__(self, root, tracker):
self.tracker = tracker
self.root = root
self.root.geometry(self.SIZE)
self.root.title(self.TITLE)
# Frame for inputs
form_frame = tk.Frame(self.root)
form_frame.pack(pady=20)
# --- Row 0: Centered Title Label ---
tk.Label(form_frame, text="Add Transaction Details:", font=(SMALL_FONT)).grid(row=0, column=0, columnspan=2, pady=10) # span across both columns
# --- Row 1: Amount Input ---
tk.Label(form_frame, text="Amount:", font=SMALL_FONT).grid(row=1, column=0, padx=10, pady=5, sticky="e")
amount_entry = tk.Entry(form_frame, width=25)
amount_entry.grid(row=1, column=1, padx=10, pady=5)
# --- Row 2: Category Input ---
tk.Label(form_frame, text="Category:", font=SMALL_FONT).grid(row=2, column=0, padx=10, pady=5, sticky="e")
category_entry = tk.Entry(form_frame, width=25)
category_entry.grid(row=2, column=1, padx=10, pady=5)
# --- Row 3: Description Input ---
tk.Label(form_frame, text="Description:", font=SMALL_FONT).grid(row=3, column=0, padx=10, pady=5, sticky="e")
description_entry = tk.Entry(form_frame, width=25)
description_entry.grid(row=3, column=1, padx=10, pady=5)
# --- Bottom Buttons Here ---
bottom_frame = tk.Frame(self.root)
bottom_frame.pack(side="bottom", pady=20)
add_button = tk.Button(bottom_frame, text="Add Transaction", width=15, height=2, command=lambda: self.save_responses(amount_entry, category_entry, description_entry))
add_button.pack(side="left", padx=10)
exit = tk.Button(bottom_frame, text="Exit", width=15, height=2, command=self.root.destroy)
exit.pack(side="left", padx=10)
def save_responses(self, amount, category, description):
try:
amount = float(amount.get())
except ValueError:
messagebox.showerror("Invalid Amount", "Please enter a valid number.")
return
category = category.get().strip()
description = description.get().strip()
if not category:
messagebox.showerror("Missing Category", "Please enter a category.")
return
new_transaction = Transaction(amount, category, description)
self.tracker.add_transaction(new_transaction)
print(f"Transaction Saved: {amount}, {category}, {description}")
self.root.destroy()
class createBalanceMenu:
SIZE = "400x150"
TITLE = "Balance"
def __init__(self, root, tracker):
self.tracker = tracker
self.root = root
self.root.geometry(self.SIZE)
self.root.title(self.TITLE)
frame = tk.Frame(self.root)
frame.pack(expand=True, anchor="center")
description = tk.Label(frame, text="Total Balance:", font=LARGE_FONT)
balance = self.tracker.total_balance()
formatted_balance = f"{CURRENCY}{balance:.2f}"
balanceText = tk.Label(frame, text=formatted_balance, font=MEDIUM_FONT)
description.pack()
balanceText.pack(pady=5)
bottom_frame = tk.Frame(self.root)
bottom_frame.pack(side="bottom", pady=10)
exit = tk.Button(bottom_frame, text="Exit", width=15, height=2, command=self.root.destroy)
exit.pack()
class createSummaryMenu:
TITLE = "Category Summary"
def __init__(self, root, size, tracker):
self.tracker = tracker
self.root = root
self.root.geometry(size)
self.root.title(self.TITLE)
form_frame = tk.Frame(self.root)
form_frame.pack(pady=20)
tk.Label(form_frame, text="Category Summary:", font=(LARGE_FONT)).grid(row=0, column=0, columnspan=2, pady=5)
summary = self.tracker.category_summary()
for row, c in enumerate(summary):
tk.Label(form_frame, text=f"{c}:", font=SMALL_FONT).grid(row=row+1, column=0, padx=5, pady=5, sticky="e")
amount = summary[c]
formatted_amount = f"{CURRENCY}{amount:.2f}"
tk.Label(form_frame, text=formatted_amount, font=SMALL_FONT).grid(row=row+1, column=1, padx=10, pady=5, sticky="e")
bottom_frame = tk.Frame(self.root)
bottom_frame.pack(pady=10)
# --- Income Overview
tk.Label(bottom_frame, text="Income:", font=(MEDIUM_FONT)).grid(row=0, column=0, padx=5, pady=5)
income = self.tracker.total_income()
formatted_income = f"{CURRENCY}{income:.2f}"
tk.Label(bottom_frame, text=formatted_income, font=(MEDIUM_FONT)).grid(row=0, column=1, padx=5, pady=5)
# --- Expenses Overview ---
tk.Label(bottom_frame, text="Expenses:", font=(MEDIUM_FONT)).grid(row=1, column=0, padx=5, pady=5)
expenses = self.tracker.total_expenses()
formatted_expenses = f"{CURRENCY}{expenses:.2f}"
tk.Label(bottom_frame, text=formatted_expenses, font=(MEDIUM_FONT)).grid(row=1, column=1, padx=5, pady=5)
# --- Net Balance ---
tk.Label(bottom_frame, text="Net Balance:", font=(MEDIUM_FONT)).grid(row=2, column=0, padx=5, pady=5)
balance = self.tracker.total_balance()
formatted_balance = f"{CURRENCY}{balance:.2f}"
tk.Label(bottom_frame, text=formatted_balance, font=(MEDIUM_FONT)).grid(row=2, column=1, padx=5, pady=5)
exit = tk.Button(bottom_frame, text="Exit", width=15, height=2, command=self.root.destroy).grid(row=3, column=0, columnspan=2, pady=5)