I'm trying to make a GUI, but for some of the instantiated object
variable names, the interpreter is looking at them as global names.
Here is an example of what I did:
class mygui:
def __init__(self, root):
self.menubar = Menu(root)
# Game Menu
self.menu1 = Menu(self.menubar, tearoff=0)
self.menu1.add_command(label="Open File", command=donothing)
self.menu1.add_separator()
self.menu1.add_command(label="Exit", command=root.quit)
self.menubar.add_cascade(label="File", menu=self.menu1)
# ignoring the rest of the program ...
when I run my example, an error shows:
"NameError: global name'menubar' is not defined"
I wonder why it doesn't work. Isn't that the way to define an object
variable?
Any response would be appreciated.