Python Forum
[Tkinter] Im embarresed to ask, but Im stuck
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Im embarresed to ask, but Im stuck
#1
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
>>>
Reply


Messages In This Thread
Im embarresed to ask, but Im stuck - by Smelt - Oct-29-2017, 08:50 AM
RE: Im embarresed to ask, but Im stuck - by Lux - Oct-29-2017, 01:00 PM
RE: Im embarresed to ask, but Im stuck - by buran - Oct-29-2017, 01:28 PM
RE: Im embarresed to ask, but Im stuck - by Smelt - Oct-30-2017, 03:22 AM
RE: Im embarresed to ask, but Im stuck - by Larz60+ - Oct-30-2017, 05:04 AM
RE: Im embarresed to ask, but Im stuck - by royer14 - Nov-20-2017, 03:22 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020