How do I use the data entered in a form?

Steve Gronicus at SGA.Ninja
Sat Aug 22 04:16:01 EDT 2020


The only thing I can add to that program as far as errors go is that "SR is
Not Defined" after the program focus is outside of any def in the last line
or two.  Is there any location where I should place "return (SR)" or a
"global SR"?

I take it that "fetch" is not an inside command or reserved word.  The code
is everything what was posted.  Nothing was indicated in the comments that
any code or def was missing.
I commented it out because it was causing the program to dump out preventing
me from exploring the error or developing code for other purposes. Maybe I
don't need it.

Still the value for SR does not seem to be visible outside any of the def
calls. The system reports that "SR is not defined" at the end of the file.

=====================================
Footnote:
If you double major in psychology and reverse psychology, to they cacel each
other out?

-----Original Message-----
From: Python-list <python-list-bounces+gronicus=sga.ninja at python.org> On
Behalf Of Peter Otten
Sent: Saturday, August 22, 2020 2:26 AM
To: python-list at python.org
Subject: Re: How do I use the data entered in a form?

Steve wrote:

> def makeform(root, fields):
>    entries = {}
>    for field in fields:
...
>    return entries
> 
> if __name__ == '__main__':
>    root = Tk()
>    ents = makeform(root, fields)

> 
> SR = (entries['Sensor_Reading'].get()) print ("SR Outside = " + SR)
> 
> ==================================
> The last two lines were guesses but they still failed.

[Always tell us how your code fails, please. If there's an exception include
it and the complete traceback in your post.]

In this case you probably get a NameError because 'entries' is a local
variable in makeform(). In the global namespace the person you copied the
code from used 'ents' -- so you have to either use ents, too,

> if __name__ == '__main__':
>    root = Tk()
     ents = makeform(root, fields)
     ...
     SR = ents['Sensor_Reading'].get()


or rename it

> if __name__ == '__main__':
>    root = Tk()
     entries = makeform(root, fields)
     ...
     SR = entries['Sensor_Reading'].get()

>  # root.bind('<Return>', (lambda event, e = ents: fetch(e)))
>                           #"fetch not defined" reported here

Again, the author of the original code probably defined a fetch() function;
if you want to use it you have to copy it into your script.


--
https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list