Skip to content

Instantly share code, notes, and snippets.

@akupar
Forked from rudrathegreat/Loading.py
Created January 17, 2025 16:46
Show Gist options
  • Save akupar/06b50f6aa7f17609f95425fc524f5b75 to your computer and use it in GitHub Desktop.
Save akupar/06b50f6aa7f17609f95425fc524f5b75 to your computer and use it in GitHub Desktop.
A Simple Loading Animation For the Command Line Using Python 3
"""
This program is designed to create
and animate a simple loading animation.
"""
from sys import stdout as terminal
from time import sleep
from itertools import cycle
from threading import Thread
done = False
def animate():
for c in itertools.cycle(['|', '/', '-', '\\']):
if done:
break
terminal.write('\rloading ' + c)
terminal.flush()
sleep(0.1)
terminal.write('\rDone! ')
terminal.flush()
t = Thread(target=animate)
t.start()
sleep(5)
done = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment