Tkinter window displaying the time?

Gary Richardson garyr at fidalgo.net
Sat Aug 25 10:49:19 EDT 2001


Is is possible to do this in a thread? I.e.:

from Tkinter import *
from time import *
import thread

def titleTime():
    now = strftime("GMT: %I:%M:%S %p", localtime(time()))
    #root.title(now)
    root.after(1000, titleTime)

root=Tk()
root.iconify()
thread.start_new(titleTime, ())
root.mainloop()

When I uncomment the line "root.title(now)" this code hangs up and I have to
exit the IDE to recover. I'm using PythonWin, ActivePython build 2.1.211.


"William Annis" <annis at biostat.wisc.edu> wrote in message
news:jtofp5nsuf.fsf at wazor.biostat.wisc.edu...
>
> "G. Willoughby" <thecalm at NOSPAM.btinternet.com> writes:
>
> > I thought of using a while 1: loop and providing a 1 second delay with
> > sleep(1) to update the title but this don't seem to be working, any
ideas???
>
>         With the while 1: loop the event handler will never have a
> chance to take over.  You want to schedule an update callback
> regularly.  Try this:
>
>
> from Tkinter import *
> from time import *
>
> def titleTime():
>     now = strftime("GMT: %I:%M:%S %p", localtime(time()))
>     root.title(now)
>     # Time in ms.
>     root.after(1000, titleTime)
>
> root=Tk()
> root.iconify()
> titleTime()
> root.mainloop()
>
>
> --
> William Annis - System Administrator - Biomedical Computing Group
> annis at biostat.wisc.edu                       PGP ID:1024/FBF64031
> Mi parolas Esperanton - La Internacian Lingvon  www.esperanto.org








More information about the Python-list mailing list