I have this program I'm trying to write, a simple application with gui: a menu and a button.
Whenever I go to run it, this is the error I get:
Traceback (most recent call last):
File "/Users/myname/Documents/School/Programming/Window.py", line 27, in <module>
app = Application()
File "/Users/myname/Documents/School/Programming/Window.py", line 14, in __init__
self.createWidgets()
File "/Users/myname/Documents/School/Programming/Window.py", line 17, in createWidgets
self.helloButton = Button (self, text='Hello', command=helloCallBack)
NameError: global name 'helloCallBack' is not defined
This is my code:
#Python 3.1
#!/Library/Frameworks/Python.framework/Versoins/3.1/Resources/Python
from tkinter import *
class Application(Frame):
helloCallBack = None
def helloCallBack():
tkMessageBox.showinfo ("Hello", "Hello, do you like my application?")
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid()
self.createWidgets()
def createWidgets(self):
self.helloButton = Button (self, text='Hello', command=helloCallBack)
self.helloButton.pack()
self.helloButton.grid()
self.menuFile = Menubutton (self, text='File')
self.menuFile.grid()
self.menuFile.hiAgain = Menu (self.menuFile, tearoff = 0)
self.menuFile["HiAgain"] = self.menuFile.hiAgain
self.menuFile.hiAgain.add_command(label="Hello", command=helloCallBack)
app = Application()
app.master.title("My Attempt at python")
app.mainloop()
Please help!