Im getting a NameError: name ' Application ' is not defined error. I want to create a simple GUI interface using tkinter for the first time. I would appreciate some insight here. Heres the code:
from tkinter import*
class Application(Frame):
def say_Yeh(self):
print("Yeh! Your button just did something!")
def createWidgets(self):
self.QUITBUTTON= Button(self)
self.QUITBUTTON['text']= 'QUIT BUTTON'
self.QUITBUTTON['command']= self.quit
self.QUITBUTTON['fg']= 'red'
self.QUITBUTTON.pack({'side' : 'left'})
self.do_something= Button(self)
self.do_something['text']= ' CLICK TO DO SOMETHING BUTTON',
self.do_something['command']= self.say_Yeh
self.do_something.pack({'side': 'left'})
def __init__(self,master= None):
Frame.__init__(self,master)
self.pack()
self.createWidgets()
root= Tk()
app= Application(master=root)
app.mainloop()
root.destroy()
Here's the error:
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>>
============ RESTART: /Users/amyheu-wong/Documents/FrameButton.py ============
Traceback (most recent call last):
File "/Users/amyheu-wong/Documents/FrameButton.py", line 3, in <module>
class Application(tk.Frame):
File "/Users/amyheu-wong/Documents/FrameButton.py", line 27, in Application
app= Application(master=root)
NameError: name 'Application' is not defined
>>>
from tkinter import*
class Application(Frame):
def say_Yeh(self):
print("Yeh! Your button just did something!")
def createWidgets(self):
self.QUITBUTTON= Button(self)
self.QUITBUTTON['text']= 'QUIT BUTTON'
self.QUITBUTTON['command']= self.quit
self.QUITBUTTON['fg']= 'red'
self.QUITBUTTON.pack({'side' : 'left'})
self.do_something= Button(self)
self.do_something['text']= ' CLICK TO DO SOMETHING BUTTON',
self.do_something['command']= self.say_Yeh
self.do_something.pack({'side': 'left'})
def __init__(self,master= None):
Frame.__init__(self,master)
self.pack()
self.createWidgets()
root= Tk()
app= Application(master=root)
app.mainloop()
root.destroy()
Here's the error:
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>>
============ RESTART: /Users/amyheu-wong/Documents/FrameButton.py ============
Traceback (most recent call last):
File "/Users/amyheu-wong/Documents/FrameButton.py", line 3, in <module>
class Application(tk.Frame):
File "/Users/amyheu-wong/Documents/FrameButton.py", line 27, in Application
app= Application(master=root)
NameError: name 'Application' is not defined
>>>