[Tutor] Global name not found, though clearly in use
Dave Angel
davea at ieee.org
Wed Jul 14 19:06:34 CEST 2010
Corey Richardson wrote:
> The entirety of
> my (incomplete and buggy) code is now available here:
> http://pastebin.com/QTNmKYC6 ......
> Hmm..If I add a few debugging lines like that into my code, I get this:
>
> Starting program
> In class Hangman
> done defs in class
> eWordEntryBox defined
> Exception in Tkinter callback
> Traceback (most recent call last):
> File "C:\Python31\lib\tkinter\__init__.py", line 1399, in __call__
> return self.func(*args)
> File "C:/Users/Corey/Desktop/HangmanApp.py", line 48, in getLetter
> self.guess = eWordEntryBox.get()
> NameError: global name 'eWordEntryBox' is not defined
>
> <snip>
>
Why do you indent the main code in this file? In particular, you've
defined the lines starting at
1.
top = tk.Tk()
2.
F = tk.Frame(top)
3.
F.pack()
as part of the class, rather than at top-level. Therefore the
eWordEntryBox is a class attribute, rather than a global symbol.
I think you need to unindent those lines, so they'll be module-level code.
There are a bunch more problems with the code, starting with the fact
that you never instantiate a Hangman instance, and continuing to missing
self parameters on some of the methods.
DaveA
More information about the Tutor
mailing list