You have other issues at play here, but to answer your question from below:
You are calling the method "reveal" prior to creating the global object "secret_text" You can try moving: x= self.submit_bttn=Button(self, text="Submit", command=self.reveal(x)) below self.secret_text = "...." You will also find that you have not defined something called "self.submit_bttn" and there are more errors beyond that, but that's past the scope of your question. On Tue, Jan 18, 2011 at 4:36 PM, David Holland <davholla2...@yahoo.co.uk>wrote: > Hi All, > I hope this makes sense > > I am trying to write a GUI where you click on a button and each time you > click on the button it shows in the entry text how many times you have > clicked. However when I changed an earlier version of the code to pass a > parameter it errors. > This works :- > > from Tkinter import * > class Application(Frame): > """GUI App""" > def __init__(self, master): > """Initialize the frame.""" > Frame.__init__(self, master) > self.grid() > self.create_widgets() > > def create_widgets(self): > self.inst_lbl=Label(self, text="Click on the button to get > instructions") > self.inst_lbl.grid(row=0, column=0, columnspan=2, sticky=W) > self.pw_lbl=Label(self, text="Password") > self.submit_bttn=Button(self, text="Submit", command=self.reveal) > self.submit_bttn.grid(row=1, column=1, columnspan=2, sticky=W) > self.secret_text=Text(self, width=35, height=5, wrap=WORD) > self.secret_text.grid(row=2, column=1, columnspan=2, sticky=W) > self.helpinfo() > > def reveal(self): > Calmexob = Calmex() > results = Calmexob.getmess() > self.secret_text.delete(0.0, END) > self.secret_text.insert(0.0,results) > > def helpinfo(self): > self.secret_text.insert(0.0,"Start") > > class Calmex(object): > > def __init__(self): > """Default arg""" > > > def getmess(self): > mesg="Test" > return mesg > > #main > root=Tk() > root.title("Test") > root.geometry("400x300") > app=Application(root) > root.mainloop() > > > But when I changed it to use a number I get an error message. > Here is the code > from Tkinter import * > class Application(Frame): > """GUI App""" > def __init__(self, master): > """Initialize the frame.""" > Frame.__init__(self, master) > self.grid() > x=0 > self.create_widgets(x) > > def create_widgets(self,x): > self.inst_lbl=Label(self, text="Click on the button to get > instructions") > self.inst_lbl.grid(row=0, column=0, columnspan=2, sticky=W) > self.pw_lbl=Label(self, text="Password") > x= self.submit_bttn=Button(self, text="Submit", > command=self.reveal(x)) > self.submit_bttn.grid(row=1, column=1, columnspan=2, sticky=W) > self.secret_text=Text(self, width=35, height=5, wrap=WORD) > self.secret_text.grid(row=2, column=1, columnspan=2, sticky=W) > self.helpinfo() > > def reveal(self, x): > Calmexob = Calmex(x) > results = Calmexob.getmess(x) > self.secret_text.delete(0.0, END) > self.secret_text.insert(0.0,results) > x=x+1 > return x > > def helpinfo(self): > self.secret_text.insert(0.0,"Start") > > class Calmex(object): > > def __init__(self,x): > """Default arg""" > > > def getmess(self,x): > mesg="Test"+str(x) > return mesg > > #main > root=Tk() > root.title("Test") > root.geometry("400x300") > app=Application(root) > root.mainloop() > > > > > > > > > > The error message is > AttributeError: Application instance has no attribute 'secret_text' > > The only change is that I have declared x and changed the function reveal > to take and pass x as an arguement. > > Thanks in advance. I hope this makes sense. > > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor