[Tkinter-discuss] Button command callback question -- Part 2

GKalman kalman_g at msn.com
Mon Jul 18 14:24:53 CEST 2011


Thanks for the replies for my earlier question. I should have stated my
question in a better way.
My question is related to SCOPE!
For example: 
#====================================
from Tkinter import *
#-------------------------------------------------
def doIt():
     print x
#------------------------------------------------
root=Tk()

btn=Button(root,text="DO",bg="cyan",command=doIt)
btn.pack(side=BOTTOM)

x=11
  

#NOTE that it works even when the mainloop() method below is commented
out!!!!
#root.mainloop()
#===================================================================

so: if
(1) there is no mainloop() 
(2) x=11 is declared in the MAIN part 
(3) command=doIt() has no argument
(4) doIt() fn appears ahead of the x=11 statement

My Question is: why x=11 is within the scope of the doIt() callback fn?

-- 
View this message in context: http://old.nabble.com/Button-command-callback-question----Part-2-tp32082790p32082790.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.



More information about the Tkinter-discuss mailing list