[Tutor] Printing in the same place
Peter Otten
__peter__ at web.de
Wed Aug 17 09:46:44 CEST 2011
brandon w wrote:
> I am trying to print in the same place to make a clock in a tkinter
> window. I will loop the following code to update the time.
>
> This seems to work but it is not printing in the same place:
>
> #!/usr/bin/python
> #Python 2.6.6
>
> import time
>
> for t in range(5):
> digits = time.strftime('%H:%M:%S')
> print "\r", digits
> time.sleep(0.1)
The print statement automatically adds a newline. Try
sys.stdout.write("\r" + digits)
sys.stdout.flush()
instead of print.
More information about the Tutor
mailing list