-
Notifications
You must be signed in to change notification settings - Fork 0
/
moneycap.py
337 lines (277 loc) · 15.4 KB
/
moneycap.py
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
from tkinter import *
import tkinter as tk
from tkinter import font
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
from tkcalendar import Calendar, DateEntry, tooltip
import matplotlib.pyplot as plt
import numpy as np
import webbrowser
from PIL import ImageTk, Image
list_of_entries = []
total = 0
housing = 0
transportation = 0
food = 0
utilities = 0
entertainment = 0
medical = 0
clothing = 0
insurance = 0
charity = 0
savings = 0
other = 0
dollars_each_category = {}
def buttonClicked(date_entry, category_entry, item_entry, expense_entry):
global total, housing, transportation, food, utilities, entertainment, medical, clothing, insurance, charity, savings, other, dollars_each_category
if expense_entry.strip() != '' and expense_entry.isdecimal() == True:
list_of_entries.append(AnEntry(date_entry, category_entry, item_entry, expense_entry))
#print("Button is clicked!")
for widget in scrollable_frame.winfo_children():
widget.destroy()
for widget in errorFrame.winfo_children():
widget.destroy()
for widget in stats_frame.winfo_children():
widget.destroy()
rownum = 0
total = 0
for i in list_of_entries:
i.displayDate().grid(row = rownum, column=0, padx=30, pady=5)
i.displayCategory().grid(row = rownum, column=1, padx=30, pady=5)
i.displayName().grid(row = rownum, column=2, padx=30, pady=5)
i.displayExpense().grid(row = rownum, column=3, padx=30, pady=5)
total += float(i.expense)
rownum += 1
if category_entry == 'Housing':
housing += round(float(expense_entry),2)
elif category_entry == 'Transportation':
transportation += round(float(expense_entry),2)
elif category_entry == "Food":
food += round(float(expense_entry),2)
elif category_entry == 'Utilities':
utilities += round(float(expense_entry),2)
elif category_entry == 'Entertainment':
entertainment += round(float(expense_entry),2)
elif category_entry == 'Medical':
medical += float(expense_entry)
elif category_entry == 'Clothing':
clothing += float(expense_entry)
elif category_entry == 'Insurance':
insurance += float(expense_entry)
elif category_entry == 'Charity':
charity += float(expense_entry)
elif category_entry == 'Savings':
savings += float(expense_entry)
elif category_entry == 'Other':
other += float(expense_entry)
stats_frame.place(relx=0.68, rely=0.58, relwidth= 0.28, relheight= 0.37)
var = StringVar()
stats_label = Label(stats_frame, relief=RAISED, textvariable=var, bg='#bfe9f5', font=('Courier', 14))
var.set("\nHousing: $" + str(round(housing,2)) + "\n Transportation: $" + str(round(transportation,2)) + "\n Food: $" + str(round(food,2)) + "\n Utilities: $" + str(round(utilities,2)) + "\n Entertainment: $" + str(round(entertainment,2)) + "\n Medical: $" + str(round(medical,2)) + "\n Clothing: $" + str(round(clothing,2)) + "\n Insurance: $" + str(round(insurance,2)) + "\n Charity: $" + str(round(charity,2)) + "\n Savings: $" + str(round(savings,2)) + "\n Other: $" + str(round(other,2)) + "\n")
stats_label.pack(fill=X)
totalvar = StringVar()
total_label = Label(stats_frame, relief=RAISED, textvariable=totalvar, bg='#bfe9f5', font=('Courier', 16 ,'bold'))
totalvar.set("\nTotal: $" + str(total) + "\n")
total_label.pack(pady=5, fill=X)
dollars_each_category = {'Housing':housing, 'Transportation':transportation, 'Food':food, 'Utilities':utilities, 'Entertainment':entertainment, 'Medical':medical, 'Clothing':clothing, 'Insurance':insurance, 'Charity':charity, 'Savings':savings, 'Other':other}
else:
errorMessage = tk.Label(errorFrame, text='Error: Please input the appropriate values.', font=('Courier'), fg='red')
errorMessage.place(relx=0.5, rely=0.5, anchor=CENTER)
class AnEntry():
def __init__(self, date, category, name, expense):
self.date = date
self.category = category
self.name = name
self.expense = expense
def displayDate(self):
label = tk.Label(scrollable_frame, text=self.date, font=('Courier', 14), relief=RAISED)
#print(self.date, self.category, self.name, self.expense)
return label
def displayCategory(self):
label = tk.Label(scrollable_frame, text=self.category, font=('Courier', 14), relief=RAISED)
return label
def displayName(self):
label = tk.Label(scrollable_frame, text=self.name, font=('Courier', 14))
return label
def displayExpense(self):
label = tk.Label(scrollable_frame, text=self.expense, font=('Courier',14))
return label
root = tk.Tk()
root.title('Money Cap')
root.iconbitmap('piggy-bank.ico')
HEIGHT = 700
WIDTH = 1000
canvas = tk.Canvas(root, height = HEIGHT, width= WIDTH)
canvas.pack()
title_frame = tk.Frame(root, bg='#C6FFBD')
title_frame.place(relwidth=1, relheight=0.1)
title_img = tk.PhotoImage(file='MoneyCapBanner.gif')
title_label = tk.Label(title_frame, image=title_img)
title_label.place(relx=0, rely=0, relwidth=0.65, relheight=1)
frame = tk.Frame(root, bg='#05FF70', bd=10)
frame.place(relx=0.05, rely=0.15, relwidth=0.6, relheight=0.65)
entry_canvas = tk.Canvas(frame)
scrollbar = tk.Scrollbar(frame, orient="vertical", command=entry_canvas.yview)
scrollable_frame = tk.Frame(entry_canvas)
scrollable_frame.bind("<Configure>", lambda e: entry_canvas.configure(scrollregion=entry_canvas.bbox("all")))
entry_canvas.create_window((0, 0), window=scrollable_frame, anchor='nw')
entry_canvas.configure(yscrollcommand=scrollbar.set)
entry_canvas.pack(side=LEFT, fill=BOTH, expand=True)
scrollbar.pack(side=RIGHT, fill = Y)
#LOWER USER ENTRY SECTION
lower_frame = tk.Frame(root, bg='#C6FFBD', bd=5)
lower_frame.place(relx=0.05, rely=0.85, relwidth=0.6, relheight=0.1)
cal = DateEntry(lower_frame, background='white', foreground='black', selectforeground='red', bordercolor='#C6FFBD')
cal.place(relx=0.025,rely=0.4, relwidth=0.2)
date_label = tk.Label(lower_frame, text="Date:", font=('Courier'), bg='#C6FFBD')
date_label.place(relx=-0.03, rely=0.1, relwidth=0.2, relheight=0.2)
category = StringVar()
dropdown_options = ["Housing", "Transportation", "Food", "Utilities", "Entertainment", "Medical", "Clothing", "Insurance", "Charity", "Savings", "Other"]
category_dropdown = OptionMenu(lower_frame, category, *dropdown_options)
category_dropdown.config(bg='#C6FFBD')
category_dropdown.place(relx=0.25, rely=0.4, relwidth=0.22, relheight=0.5)
category.set(dropdown_options[10])
category_label = tk.Label(lower_frame, text="Category:", font=('Courier'), bg='#C6FFBD')
category_label.place(relx=0.22, rely=0.1, relwidth=0.2, relheight=0.2)
item = tk.Entry(lower_frame, highlightbackground='#C6FFBD')
item.place(relx=0.5, rely =0.4, relwidth=0.2, relheight=0.5)
item_label = tk.Label(lower_frame, text="Item Name:", font=('Courier'), bg='#C6FFBD')
item_label.place(relx=0.47, rely=0.1, relwidth=0.2, relheight=0.2)
expense = tk.Entry(lower_frame, highlightbackground='#C6FFBD')
expense.place(relx=0.74, rely=0.4, relwidth=0.125, relheight=0.5)
expense_label = tk.Label(lower_frame, text="Expense($):", font=('Courier'), bg='#C6FFBD')
expense_label.place(relx=0.71, rely=0.1, relwidth=0.2, relheight=0.2)
button = tk.Button(lower_frame, text="+", highlightbackground='#C6FFBD', command=lambda: buttonClicked(cal.get_date(), category.get(), item.get(), expense.get()))
button.place(relx=0.95, rely=0.2, relwidth=0.08, relheight=0.8, anchor='n')
#PIE CHART
def filterZeroNames(dict):
newNameList = []
for key in dict:
if dict[key] != 0:
newNameList.append(key)
return newNameList
def filterZeroValues(dict):
newValueList = []
for value in dict.values():
if value != 0:
newValueList.append(value)
return newValueList
def plot():
fig = Figure(figsize = (5, 5,), dpi =60)
y = filterZeroValues(dollars_each_category)
plot1 = fig.add_subplot(111)
plot1.pie(y, labels = filterZeroNames(dollars_each_category), shadow=True, textprops={'fontsize': 11})
plt.show()
canvas = FigureCanvasTkAgg(fig, master=chart_frame)
canvas.draw()
canvas.get_tk_widget().place(relx=0, rely=0.05, relwidth=1, relheight=0.8)
toolbar = NavigationToolbar2Tk(canvas, chart_frame)
toolbar.update()
toolbar.place(relx=0, rely=0.85, relwidth=1, relheight=0.15)
chart_frame = tk.Frame(root, bd=10, bg='#05FF70')
chart_frame.place(relx=0.68, rely=0.15, relwidth=0.28, relheight=0.4)
plot_button = Button(master=root, command=plot, text='Display Pie Chart', font=('Courier', 12), highlightbackground='#05FF70')
plot_button.place(relx=0.82,rely=0.15, anchor='n')
#Error Message
errorFrame = tk.Frame(root)
errorFrame.place(relx=0.05, rely=0.95, relwidth=0.6, relheight=0.03)
#Statistics Frame
stats_frame = tk.Frame(root, bd=10, bg='#05FF70')
#NAV BAR
def go_advice():
advice_frame.place(rely=0.1, relwidth=1, relheight=0.9)
moreinfo_frame.place_forget()
def go_home():
advice_frame.place_forget()
moreinfo_frame.place_forget()
def go_moreinfo():
moreinfo_frame.place(rely=0.1, relwidth=1, relheight=0.9)
advice_frame.place_forget()
percentage = 0.2
def calculate_recommendation(question):
recommended_savings = round(question * percentage, 2)
sentence = "Your recommended savings based on the amount you entered is $" + str(recommended_savings)
recommendation_sentence = tk.Label(advice_frame,text=sentence, anchor="n")
recommendation_sentence.place(relx=0.25, rely=0.6, relheight=0.04, relwidth=0.5)
# Advice Button
advice_frame = tk.Frame(root, bg= '#32739c')
advice_button = Button(title_frame, text="Advice", command=go_advice, highlightbackground='#C6FFBD')
advice_button.place(relx=0.78, rely=0.4)
savings_frame = tk.Frame(advice_frame, bd=15, bg='#6bf5ff')
savings_frame.place(relx=0.5, rely=0.08, relwidth=0.6, relheight=0.7, anchor='n')
savings2_frame = tk.Frame(savings_frame)
savings2_frame.place(relwidth=1, relheight=1)
savings_img = ImageTk.PhotoImage(Image.open('savingsbg.gif'))
#src https://www.switchtv.ke/Uploads/f85c15c1-4e06-4762-babf-13209be71567.jpg
savings_bg = tk.Label(savings_frame, image=savings_img)
savings_bg.pack()
advice = tk.Entry(advice_frame, highlightthickness=0)
advice.place(relx = 0.45, rely = 0.5, anchor="n")
advice2_button = Button(advice_frame, text="Enter", highlightbackground='#6bf5ff', command=lambda:calculate_recommendation(float(advice.get())))
advice2_button.place(relx = 0.54, rely = 0.497)
advice_title = tk.Label(advice_frame, text= "Savings Advice", font=('Courier', 30, 'bold'), anchor='n')
advice_title.place(relx=0.37, rely=0.12)
question = tk.Label(advice_frame, text="Please enter your monetary limit/income in the entry bar below.")
question.pack(pady=200)
# This is for the positioning of the text contained in the about frame
# Home Button
home_button = Button(title_frame, text="Home", command=go_home, highlightbackground='#C6FFBD')
home_button.place(relx=0.7, rely=0.4)
# More info Button
moreinfo_frame = tk.Frame(root, bg= '#239e5c')
moreinfo_button = Button(title_frame, text="More Info", command=go_moreinfo, highlightbackground='#C6FFBD')
moreinfo_button.place(relx=0.86, rely=0.4)
aboutFrame = tk.Frame(moreinfo_frame, bg='#05FF70', bd=10)
aboutFrame.place(relx=0.08, rely=0.05, relwidth=0.85, relheight=0.3)
aboutFrame2 = tk.Frame(aboutFrame, bg='white')
aboutFrame2.place(relwidth=1, relheight=1)
about_label = tk.Label(aboutFrame2, text="About Money Cap", font=('Courier', 16, 'bold'))
about_text = tk.Label(aboutFrame2, text="It’s easy to spend money, but when it comes to saving, budgeting, and planning—well...that other part can be a little complicated.\n Introducing Money Cap: \n A tool to organize monetary expenses and learn how to budget. \n This app allows you to input your purchases, organize your items into categories, and allocate your savings. With a simple and systematic layout and personalized financial advice, Money Cap is an effective tool to advance your financial literacy skills.", font=('Arial', 14), wraplength=850, justify=CENTER)
about_label.pack()
about_text.pack()
linksFrame = tk.Frame(moreinfo_frame, bg='#05FF70', bd=10)
linksFrame.place(relx=0.05, rely=0.4, relwidth=0.5, relheight=0.55)
linksFrame2 = tk.Frame(linksFrame, bg='white')
linksFrame2.place(relwidth=1, relheight=1)
links_label = tk.Label(linksFrame2, text="Links to Learn More", font=('Courier', 16, 'bold'))
links_label.pack()
def callback(url):
webbrowser.open_new_tab(url)
# Link 1 - 50/30/20 rule
link1 = Label(linksFrame2, text = "50/30/20 Rule", fg = "blue", cursor = "hand2", font=('Arial', 16))
link1.pack(pady=5)
link1.bind("<Button-1>", lambda e: callback("https://www.nerdwallet.com/article/finance/how-to-budget"))
# Link 2 - Budgeting for college students
link2 = Label(linksFrame2, text = "Budgeting For College Students", fg = "blue", cursor = "hand2", font=('Arial', 16))
link2.pack(pady=5)
link2.bind("<Button-1>", lambda e: callback("https://college.lovetoknow.com/Amount_of_Spending_Money_a_College_Student_Needs"))
# Link 3 - Budgeting for Teens: 14 Tips For Growing Your Money Young
link3 = Label(linksFrame2, text = "Budgeting for Teens: 14 Tips For Growing Your Money Young", fg = "blue", cursor = "hand2", font=('Arial', 16))
link3.pack(pady=5)
link3.bind("<Button-1>", lambda e: callback("https://mint.intuit.com/blog/budgeting/budgeting-for-teens/"))
# Link 4 - What Car Payment Can You Afford?
link4 = Label(linksFrame2, text = "What Car Payment Can You Afford?", fg = "blue", cursor = "hand2", font=('Arial', 16))
link4.pack(pady=5)
link4.bind("<Button-1>", lambda e: callback("https://www.nerdwallet.com/article/loans/auto-loans/much-car-payment"))
# Link 5 - 5 Ways Teens Can Start Building Credit Right Now
link5 = Label(linksFrame2, text = "5 Ways Teens Can Start Building Credit Right Now", fg = "blue", cursor = "hand2", font=('Arial', 16))
link5.pack(pady=5)
link5.bind("<Button-1>", lambda e: callback("https://www.credit.com/blog/how-high-school-students-can-start-building-credit-asap-166771/"))
# Link 6 - Hard credit inquiry vs. soft credit inquiry: What they are and why they matter
link6 = Label(linksFrame2, text = "Hard credit inquiry vs. soft credit inquiry: \nWhat they are and why they matter", fg = "blue", cursor = "hand2", font=('Arial', 16))
link6.pack(pady=5)
link6.bind("<Button-1>", lambda e: callback("https://www.creditkarma.com/advice/i/hard-credit-inquiries-and-soft-credit-inquiries"))
# Link 7 - How to Invest Money
link7 = Label(linksFrame2, text = "How to Invest Money", fg = "blue", cursor = "hand2", font=('Arial', 16))
link7.pack(pady=5)
link7.bind("<Button-1>", lambda e: callback("https://www.nerdwallet.com/article/investing/how-to-invest-money"))
# Link 8 - How to Motivate Yourself to Improve Your Finances
link8 = Label(linksFrame2, text = "How to Motivate Yourself to Improve Your Finances", fg = "blue", cursor = "hand2", font=('Arial', 16))
link8.pack(pady=5)
link8.bind("<Button-1>", lambda e: callback("https://www.bankrate.com/personal-finance/motivate-yourself-to-improve-finances/"))
imgFrame = tk.Frame(moreinfo_frame, bd=10, bg='#05FF70')
imgFrame.place(relx=0.6, rely=0.4, relwidth=0.35, relheight=0.55)
topicsimg = ImageTk.PhotoImage(Image.open('financial-literacy.gif'))
moneyTopics = tk.Label(imgFrame, image=topicsimg, anchor='n')
moneyTopics.pack()
root.mainloop()