[Tutor] Simple GUI

myles broomes mylesbroomes at hotmail.co.uk
Sun Mar 4 12:59:55 CET 2012


Im trying to code a simple GUI but I'm having a bit of a problem. Heres my code: from tkinter import *class Application(Frame):
        def __init__(self,master=None):
                Frame.__init__(self,master)
                self.grid(sticky=N+S+E+W)
                self.createWidgets()        def createWidgets(self):
                top=self.winfo_toplevel()
                top.rowconfigure(0,weight=1)
                top.columnconfigure(0,weight=1)
                self.rowconfigure(0,weight=1)
                self.columnconfigure(0,weight=1)
                self.Nothing = Button(self,text='Nothing',activebackground='red',cursor='gumby',command=self.configure())
                self.Nothing.grid(row=0,column=0,sticky=N+S+E+W)        def configure(self):
                self.Nothing.configure(text='Hello!')app = Application()
app.master.title("The Nothing Button")
app.mainloop() when I run the batch file, i get this error:Traceback (most recent call last):
  File "C:\Python32\gui2.py", line 21, in <module>
    app = Application()
  File "C:\Python32\gui2.py", line 7, in __init__
    self.createWidgets()
  File "C:\Python32\gui2.py", line 15, in createWidgets
    self.Nothing = Button(self,text='Nothing',activebackground='red',cursor='gumby',command=self.configure())
  File "C:\Python32\gui2.py", line 19, in configure
    self.Nothing.configure(text='Hello!')
AttributeError: 'Application' object has no attribute 'Nothing' What I get from that is that its claiming that my Application class doesnt have an attribute called 'Nothing' but I clearly defined it in the 'createWidgets()' method. Can anyone explain to me exactly what the problem is. Thanks.

Myles Broomes
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120304/644ecb18/attachment.html>


More information about the Tutor mailing list