![]() |
[Tkinter] Im embarresed to ask, but Im stuck - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] Im embarresed to ask, but Im stuck (/thread-5930.html) |
Im embarresed to ask, but Im stuck - Smelt - Oct-29-2017 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 >>> RE: Im embarresed to ask, but Im stuck - Lux - Oct-29-2017 I tried running the code on my computer and it didn't give me any errors... RE: Im embarresed to ask, but Im stuck - buran - Oct-29-2017 (Oct-29-2017, 01:00 PM)Lux Wrote: I tried running the code on my computer and it didn't give me any errors... I guess OP has wrong indentation problem, but without using BBcode and thus preserving the original indentation it;s not possible to be certain. RE: Im embarresed to ask, but Im stuck - Smelt - Oct-30-2017 Interesting, hmm what can it be. I didn't think anything was wrong with the code. I tried this on ubuntu 14.04, Windows 10 and my mac and couldn't run it without an error. So you see the GUI interface after running the code? Sorry, I need to learn how to post in BBcode. Can you point me in the write direction? I'll try an figure it out on my own for now.. BTW: thank you for looking into it. I appreciate it as I am trying to learn without being called dumb.. THANK YOU buron and Lux! It was an indentation issue. I'll be sure to post properly on my next post. Thank you again, you guys made my evening :) RE: Im embarresed to ask, but Im stuck - Larz60+ - Oct-30-2017 click Help/ Rules then BBCODE RE: Im embarresed to ask, but Im stuck - royer14 - Nov-20-2017 hi, try with this little fix root= Tk() app1 = Application(parent=root) # parent to root app= Application(master=root) # edit it app.mainloop() root.destroy() |