Text Animation
Andrew Henshaw
andrew.henshaw at gtri.gatech.edu
Sun Jan 25 23:31:42 EST 2004
Fazer wrote:
> Hello,
>
> I was wondering if anyone has done any simple text-based animation?
>
> I mean things such as text-based pre-loaders. One example would be
> when you use the *nix utility called `wget.` You get that fancy "
> ====> " type of animation as you download a large file. Or maybe even
> a rotating " | " that I have seen before in some installation
> programs.
>
> Any ideas how these effects can be achieved?
>
> Thanks a lot!
>
> Faizan
I use this:
###################################
import sys
class Spinner:
SYMBOLS = '|/-\\'
def __init__(self):
self.index = 0
def __call__(self):
sys.stdout.write(Spinner.SYMBOLS[self.index]+'\b')
self.index = (self.index+1) % len(Spinner.SYMBOLS)
###################################
And call it like this:
###################################
if __name__ == '__main__':
import time
spin = Spinner()
for i in range(100):
spin()
time.sleep(0.1)
###################################
This looks fine under the Win2K cmd window; but, as pointed out in another
reply, you may need to turn off the cursor. I just tested it under Konsole
on Linux, and the block cursor doesn't allow the effect to show.
--Andy
More information about the Python-list
mailing list