Threading and tkinter
Scott David Daniels
Scott.Daniels at Acm.Org
Thu Feb 19 18:19:42 EST 2009
gert wrote:
> Hope you do not mind ignoring part of answers, so I can figure out
> more why things work the way they are.
> This two examples work, what i do not understand is that in function
> display i do not have to declare root, v or x ?
...
>
> x=0
> def weegbrug():
> global x
> while True:
> x=x+1
> sleep(0.5)
> start_new_thread(weegbrug,())
>
> def display():
> v.set(x)
> root.after(500, lambda:display())
1) Note that x, v, and root are read and manipulated, but not written.
So, they do not need to be declared global (global is only needed
to declare writable global names).
2) The last statement could more easily be written:
root.after(500, display)
...
> root.after(500, lambda:display())
Again you can write this:
root.after(500, display)
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list