Python how to make simple animated loading while process is running

前端 未结 6 1788
广开言路
广开言路 2020-12-13 03:30

This is pretty much what I have right now:

import time
import sys

done = \'false\'
#here is the animation
def animate():
    while done == \'false\':
               


        
6条回答
  •  旧巷少年郎
    2020-12-13 04:10

    import sys, time, threading
    
    def your_function_name() :
        # do something here
    
    def loadingAnimation(process) :
        while process.isAlive() :
            chars = "/—\|" 
            for char in chars:
                sys.stdout.write('\r'+'loading '+char)
                time.sleep(.1)
                sys.stdout.flush()
    
    loading_process = threading.Thread(target=your_function_name)
    loading_process.start()
    animated_loading(loading_process)
    loading_process.join()
    

提交回复
热议问题