global name 'fetchone' is not defined (GUI TKINTER PYTHON)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raaaaaandalls
    New Member
    • Nov 2017
    • 1

    global name 'fetchone' is not defined (GUI TKINTER PYTHON)

    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 = investmentAmoun t * (1 + monthlyInterest Rate) ^ 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(en tries):

    # period rate:

    r = float(int(entri es['Investment Amount'].get())*(1+int( entries['Interest Rate'].get()))^int(en tries['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=T OP, fill=X, padx=5, pady=5)

    lab.pack(side=L EFT)

    ent.pack(side=R IGHT, expand=YES, fill=X)

    entries[field] = ent

    return entries

    if __name__ == '__main__':

    root = Tk()

    ents = makeform(root, fields)

    root.bind('<Ret urn>', (lambda event, e=ents: fetchone(e)))

    b1 = Button(root, text='Calculate ',

    command=(lambda e=ents: future_value(e) ))

    b1.pack(side=LE FT, padx=5, pady=5)

    b3 = Button(root, text='Quit', command=root.qu it)

    b3.pack(side=LE FT, 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
Working...