COMPOUND INTEREST CALCULATOR EXE
1 file(s) 8.64 MB
COMPOUND INTEREST CALCULATOR
PYTHON
COMPOUND INTEREST CALCULATOR
The compound interest calculator is a lot like the flooring calculator with the main visible difference being how the total is output at the bottom of the app. I used the same color scheme and same basic layout. The code is from a slightly earlier project as you will see on the Python home page, also created about a week prior to starting to learn tkinter. With each project I try to implament a new feature in order to learn an new skill or new widget or to simply get used to how Python is structured in tkinter and how the different libraries fit together as a beginner.
PYTHON
import tkinter
from tkinter import BOTH, END
root = tkinter.Tk()
root.title(‘Compound Interest Calculator’)
root.iconbitmap(‘investment.ico’)
root.geometry(‘500×500’)
root.resizable(0,0)
root.config(bg=’#2b2d2f’)
# BUTTON FUNCTION THAT CLEARS THE TOTAL OUTPUT LOCATION
def delete():
output.pack_forget()
r.destroy()
# FUNCTION THAT CALCULATES THE TOTAL USING THE COMPOUND INTEREST FORMULA
def total():
global output
r = float(r_rate.get())
n = float(n_peryear.get())
t = float(t_years.get())
p = float(p_invest.get())
percentage = r/100
compound = (percentage/n+1)**(n*t)*p
# OUTPUT PRINT OUT
output = tkinter.Label(bottom_frame, text=round(compound, 2), font=(‘Cambria’, 26, ‘bold’), bg=’#2b2d2f’, fg=’#00ffff’)
output.pack(pady=20)
# CLEARING THE INPUT BOXES AFTER BUTTON PRESS
r_rate.delete(0, END)
n_peryear.delete(0, END)
t_years.delete(0, END)
p_invest.delete(0, END)
# THE WINDOW IS DIVIDED INTO A TOP AND BOTTOM FRAME DEFINE BELOW
top_frame = tkinter.Frame(root, width=400, height=400, bg=’#00ffff’)
top_frame.pack(pady=10, padx=10, expand=True, fill=BOTH)
top_frame.propagate(0)
bottom_frame = tkinter.LabelFrame(root, text=’EURO TOTAL’, fg=’#00ffff’, width=400, height=100, bg=’#2b2d2f’, font=(‘Cambria’, 12, ‘bold’))
bottom_frame.pack(pady=20, padx=10, expand=True, fill=BOTH)
bottom_frame.propagate(0)
# DEFINING WHICH BOXES ARE FOR WHICH DETAILS FOR THE INPUT OF THE USER
r_label = tkinter.Label(top_frame, text=’Interest rate percentage’, bg=’#00ffff’, font=(‘Cambria’, 12, ‘bold’))
r_label.grid(row=1, column=0, sticky=’w’, padx=(50,0))
n_label = tkinter.Label(top_frame, text=’Compound periods per year:’, bg=’#00ffff’, font=(‘Cambria’, 12, ‘bold’))
n_label.grid(row=2, column=0, sticky=’w’, padx=(50,0))
t_label = tkinter.Label(top_frame, text=’Amount of years invested over:’, bg=’#00ffff’, font=(‘Cambria’, 12, ‘bold’))
t_label.grid(row=3, column=0, sticky=’w’, padx=(50,0))
p_label = tkinter.Label(top_frame, text=’Your initial investment:’, bg=’#00ffff’, font=(‘Cambria’, 12, ‘bold’))
p_label.grid(row=4, column=0, sticky=’w’, padx=(50,0))
# ENTRY BOXES FOR THE USERS INPUTS
r_rate = tkinter.Entry(top_frame, width=20)
n_peryear = tkinter.Entry(top_frame, width=20)
t_years = tkinter.Entry(top_frame, width=20)
p_invest = tkinter.Entry(top_frame, width=20)
r_rate.grid(row=1, column=2, pady=10, padx=10)
n_peryear.grid(row=2, column=2, pady=10, padx=10)
t_years.grid(row=3, column=2, pady=10, padx=10)
p_invest.grid(row=4, column=2, pady=10, padx=10)
# CALCULATING BUTTON
comp_btn = tkinter.Button(top_frame, text=’CALCULATE TOTAL’, font=(‘Cambria’, 13, ‘bold’), bg=’#2b2d2f’, fg=’#00ffff’, activeforeground=’#00ffff’, activebackground=’#000000′, command=total)
comp_btn.grid(row=5,column=0, columnspan=3, pady=20, ipadx=40, padx=0)
# DELETE BUTTON
del_btn = tkinter.Button(top_frame, text=’X’, font=(‘Cambria’, 13, ‘bold’), bg=’#2b2d2f’, fg=’#00ffff’, activeforeground=’#00ffff’, activebackground=’#000000′, command=delete)
del_btn.grid(row=5,column=2, ipadx=5)
# THE LOGO AT THE TOP AND CENTER OF THE WINDOW
image = tkinter.PhotoImage(file=(‘investment50.png’))
im_label = tkinter.Label(top_frame, image=image, bg=’#00ffff’)
im_label.grid(row=0, column=0, pady=10, columnspan=3)
root.mainloop()