By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

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

P: 1
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)


row.pack(side=TOP, fill=X, padx=5, pady=5)


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)


but I get this error: global name 'fetchone' is not defined

The professor has us coding with Pycharm which is 2.6 I believe
Nov 9 '17 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.