I was given this question to solve from my Intro to Python professor.
Tkinter: (Create an investment-value calculator) Write a program that calculates the future value of an investment at a given interest rate for a specified number of years. The formula for the calculation is as follows:
futureValue = investmentAmount * (1 + monthlyInterestRate) ^ years * 12
Use text fields for users to enter the investment amount, years, and interest rate. Display the future amount in a text field when the user clicks the Calculate button.
So far I have:
from Tkinter import *
fields = ('Investment Amount', 'Years', 'Interest Rate', 'Future Value')
def future_value(entries):
# period rate:
r = float(int(entries['Investment Amount'].get())*(1+int(entries['Interest Rate'].get()))^int(entries['Years'].get())*12)
entries['Future Value'].delete(0,END)
entries['Future Value'].insert(0, r)
def makeform(root, fields):
entries = {}
for field in fields:
row = Frame(root)
lab = Label(row, width=22, text=field+": ", anchor='w')
ent = Entry(row)
ent.insert(0,"0")
row.pack(side=TOP, fill=X, padx=5, pady=5)
lab.pack(side=LEFT)
ent.pack(side=RIGHT, expand=YES, fill=X)
entries[field] = ent
return entries
if __name__ == '__main__':
root = Tk()
ents = makeform(root, fields)
root.bind('<Return>', (lambda event, e=ents: fetchone(e)))
b1 = Button(root, text='Calculate',
command=(lambda e=ents: future_value(e)))
b1.pack(side=LEFT, padx=5, pady=5)
b3 = Button(root, text='Quit', command=root.quit)
b3.pack(side=LEFT, padx=5, pady=5)
root.mainloop()
but I get this error: global name 'fetchone' is not defined
The professor has us coding with Pycharm which is 2.6 I believe