RES: While loop and time.sleep function
Alves, Carlos Alberto - Coelce
calves at coelce.com.br
Sat Feb 23 08:50:02 EST 2002
Thanks for your help!
But, for me, it only works properly under interactive sections (don't forget
I'm under Windows ;-)).
So, to make it works as I desire (accepting 'double-click' and 'enter' to
launching application) I just put two small lines in your code(see below).
Now, the code is running just fine.
> -----Mensagem original-----
> De: Eric Brunel [mailto:eric.brunel at pragmadev.com]
> Enviada em: quinta-feira, 21 de fevereiro de 2002 16:42
> Assunto: Re: While loop and time.sleep function
>
>
> Hi,
>
> Alves, Carlos Alberto - Coelce wrote:
> > Hi all,
> > I tray to make a simple clock program ( see the code below ).
> > Can someone explain to me why code 01 works while code 02 doesn't
> [snip]
>
> Eeer, in fact both codes didn't work... At least on my Linux
> box. The first
> problem is that there is no mainloop, so Tk never actually
> starts. The
> second problem is that since the control never returns to Tk
> (because of
> the "while 1"), Tk never gets a chance to refresh the
> display. So you must
> explicitely refresh it manually:
>
> -----------------------
> from Tkinter import *
> import time
>
> class Clock:
> def __init__(self,root):
> self.lb=Label(root,padx=5,pady=5,fg='blue',font=('Times',20))
> self.lb.pack()
> self.ck()
> self.update()
> def ck(self):
> self.lb.configure(text=time.asctime()[11:19])
> # Refresh the display; otherwise, nothing happens...
> self.lb.update_idletasks()
> def update(self):
> while 1:
> self.ck()
> time.sleep(1)
>
> if __name__=='__main__':
> root=Tk()
> root.title('Clock')
root.update()
> Clock(root)
root.update()
> # Run Tk main loop
> root.mainloop()
> -------------------------------
>
> HTH
> - eric -
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20020223/6f8095b7/attachment.html>
More information about the Python-list
mailing list