Created
August 1, 2018 13:19
-
-
Save Thanatoz-1/c906b702e4b7c32bab1fcede972d2399 to your computer and use it in GitHub Desktop.
Code for creating loading animation in python script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import threading | |
import time | |
import sys | |
done = False | |
#here is the animation | |
def animate(): | |
for c in itertools.cycle(['|', '/', '-', '\\']): | |
if done: | |
break | |
sys.stdout.write('\rloading ' + c) | |
sys.stdout.flush() | |
time.sleep(0.1) | |
sys.stdout.write('\rDone! ') | |
t = threading.Thread(target=animate) | |
t.start() | |
#long process here | |
time.sleep(10) | |
done = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment