confusion between global names and instantiated object variable names
Piet van Oostrum
piet at cs.uu.nl
Fri Oct 14 17:20:12 EDT 2005
>>>>> "wanwan" <ericwan78 at yahoo.com> (w) wrote:
>w> I'm trying to make a GUI, but for some of the instantiated object
>w> variable names, the interpreter is looking at them as global names.
>w> Here is an example of what I did:
>w> class mygui:
>w> def __init__(self, root):
>w> self.menubar = Menu(root)
>w> # Game Menu
>w> self.menu1 = Menu(self.menubar, tearoff=0)
>w> self.menu1.add_command(label="Open File", command=donothing)
>w> self.menu1.add_separator()
>w> self.menu1.add_command(label="Exit", command=root.quit)
>w> self.menubar.add_cascade(label="File", menu=self.menu1)
>w> # ignoring the rest of the program ...
>w> when I run my example, an error shows:
>w> "NameError: global name'menubar' is not defined"
If it talks about global name, it can't be self.menubar or
anything.menubar. So there must be a soloist menubar reference somewhere.
Doesn't it tell you the line number?
--
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org
More information about the Python-list
mailing list