Skip to content

Instantly share code, notes, and snippets.

@gbnk0
Forked from kholis/cursor_animation.py
Created May 22, 2016 00:59
Show Gist options
  • Save gbnk0/88431df04bd8bd163a3a8b2e86f2b866 to your computer and use it in GitHub Desktop.
Save gbnk0/88431df04bd8bd163a3a8b2e86f2b866 to your computer and use it in GitHub Desktop.
Python Text Cursor Animation
#!/usr/bin/env python
# taken from: http://stackoverflow.com/questions/7039114/waiting-animation-in-command-prompt-python
import threading
import time
class CursorAnimation(threading.Thread):
def __init__(self):
self.flag = True
self.animation_char = "|/-\\"
self.idx = 0
threading.Thread.__init__(self)
def run(self):
while self.flag:
print "Processing... ",
print self.animation_char[self.idx % len(self.animation_char)] + "\r",
self.idx += 1
time.sleep(0.1)
def stop(self):
self.flag = False
if __name__ == '__main__':
spin = CursorAnimation()
# Start Animation
spin.start()
# Do something here
# Example: sleep
time.sleep(5)
# Stop Animation
spin.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment