Jan-24-2020, 03:50 PM
(This post was last modified: Jan-24-2020, 03:53 PM by Gribouillis.)
You can do this with threading. My logic is 1) start animation in a different thread, 2) run function 1 3) stop animation. Read this page to start learning about threading in python
import threading import time event = threading.Event() def animation(): bar = [ " [= ]", " [ = ]", " [ = ]", " [ = ]", " [ = ]", " [ =]", " [ = ]", " [ = ]", " [ = ]", " [ = ]", ] i = 0 while True: print(bar[i % len(bar)], end="\r") was_set = event.wait(timeout=0.2) if was_set: break i += 1 def function1(): time.sleep(4) event.clear() anim = threading.Thread(target=animation) anim.start() function1() event.set() anim.join() # <-- wait for anim to terminate print()