I have a problem with the eval function in python. I have a window in tinker that returns me a string value. I pass them to eval and I get a syntax error. In the name field, enter ‘abc’. Why?
from tkinter import *
from tkinter.messagebox import showerror
fieldnames = ('name', 'age', 'job', 'pay')
def makeWidgets():
global entries
window = Tk()
window.title('People Shelve')
form = Frame(window)
form.pack()
entries = {}
for (ix, label) in enumerate(('key',) + fieldnames):
lab = Label(form, text=label)
ent = Entry(form)
lab.grid(row=ix, column=0)
ent.grid(row=ix, column=1)
entries[label] = ent
Button(window, text="Update", command=updateRecord).pack(side=LEFT)
Button(window, text="Quit", command=window.quit).pack(side=RIGHT)
return window
def updateRecord():
for field in fieldnames:
text = entries[field].get()
eval(text) # ERROR invalid syntax
window = makeWidgets()
window.mainloop()
I want to find out why I’m getting an error. I want this error explained to me.
New contributor
Anina is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.