[Tkinter-discuss] A Button command callback question...
Michael Lange
klappnase at web.de
Mon Jul 18 13:53:42 CEST 2011
Hi,
Thus spoketh GKalman <kalman_g at msn.com>
unto us on Sun, 17 Jul 2011 20:34:22 -0700 (PDT):
>
> The following code fragment works OK. Question: why?
> #======================================
> from Tkinter import *
> root=Tk()
>
> lbl=Label(root,text='1').pack()
>
> def doIt():
> lbl.config(bg="yellow")
>
> btn=Button(root,text="do", bg="cyan",command=doIt).pack()
>
> root.mainloop()
> #=======================================
> My question is: how is the instance lbl.config(...) recognized in the
> doIt callback fn when called from the main w/o an argument referencing
> lbl?
When I run this example and hit the button I get:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1413, in __call__
return self.func(*args)
File "test6.py", line 8, in doIt
lbl.config(bg="yellow")
AttributeError: 'NoneType' object has no attribute 'config'
as one would expect.
Regards
Michael
.-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-.
"What happened to the crewman?"
"The M-5 computer needed a new power source, the crewman merely
got in the way."
-- Kirk and Dr. Richard Daystrom, "The Ultimate Computer",
stardate 4731.3.
More information about the Tkinter-discuss
mailing list