[Tutor] How to hide cursor in Terminal?

Hugo Arts hugo.yoshi at gmail.com
Fri Feb 17 13:43:28 CET 2012


On Fri, Feb 17, 2012 at 12:38 PM, brandon w <bbbgggwww at gmail.com> 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?
>
> I am using gnome-terminal and Python 2.6.6.
>
>
> #!/usr/bin/python
>
> import time
> import sys
> import os
>
> def countd():
>
>     seconds = 59
>     minutes = 4
>     five_minutes = 0
>
>     os.system('clear')
>
>     while five_minutes != 300:
>         sys.stdout.write("%d:%02.f\r" % (minutes, seconds))
>         sys.stdout.flush()
>         seconds -= 1
>         if seconds == -1:
>             minutes -= 1
>             seconds = 59
>
>         five_minutes += 1
>         time.sleep(1)
>
> countd()
>
>
>
> Brandon
>

I believe that the curses[1] library can do this, though that may be
somewhat complex (curses is essentially a GUI toolkit for the
terminal). You should probably read up on the tutorial mentioned
there.

HTH,
Hugo

[1] http://docs.python.org/library/curses.html


More information about the Tutor mailing list