Python how to make simple animated loading while process is running

前端 未结 6 1799
广开言路
广开言路 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

    Try this one

    import time
    import sys
    
    
    animation = "|/-\\"
    
    for i in range(100):
        time.sleep(0.1)
        sys.stdout.write("\r" + animation[i % len(animation)])
        sys.stdout.flush()
        #do something
    print("End!")
    

提交回复
热议问题