[Tutor] How to hide cursor in Terminal?

Alan Gauld alan.gauld at btinternet.com
Fri Feb 17 20:00:07 CET 2012


On 17/02/12 11:38, brandon w wrote:
> I made a timer that counts down from five minutes. This code runs fine
> but I a seeing a cursor blinking on the first number as the code is
> running. How do I avoid this?
>

Try putting the carriage return at the start of the line. You print the 
line then reset the cursor to the beginning. You want to reset the 
cursor then print leaving the cursor at the end of the line(I assume?)
If you want to get rid of the cursor entirely then I think you might be 
able to do it via a set tty command or similar - but why would you?!
And if you do, don't forget to reset it after you finish!

>      while five_minutes != 300:
>          sys.stdout.write("%d:%02.f\r" % (minutes, seconds))

           sys.stdout.write("\r%d:%02.f" % (minutes, seconds))

That might do it for you.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list