While loop and time.sleep function

Alves, Carlos Alberto - Coelce calves at coelce.com.br
Thu Feb 21 16:42:15 CET 2002


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
----------------------------------------------------------------------------
---------------------
Code 01
----------------------------------------------------------------------------
---------------------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])
	def update(self):
		while 1:
			self.ck()
			print "",
if __name__=='__main__':
	root=Tk()
	root.title('Clock')
	Clock(root)
----------------------------------------------------------------------------
---------------------
Code 02
----------------------------------------------------------------------------
---------------------
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])
	def update(self):
		while 1:
			self.ck()
			time.sleep(1)
if __name__=='__main__':
	root=Tk()
	root.title('Clock')
	Clock(root)

Carlos Alberto
COELCE/DPRON-Departamento de Projetos e Obras Norte
Fone: 677- 2228
e-mail: calves at coelce.com.br
\|||/
(o o)
--ooo0-(_)-0ooo--

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20020221/add22039/attachment.html>


More information about the Python-list mailing list