六種酷炫Python運行進度條(進度顯示動畫)

六種酷炫Python運行進度條(進度顯示動畫)

六種酷炫Python運行進度條(進度顯示動畫)


資料來源:https://mp.weixin.qq.com/s?__biz=MzU5Mjg2OTQ1MA==&mid=2247491100&idx=3&sn=3f8959e040ecf02c9c53dbbf78e85431&chksm=fe187f39c96ff62f4366dd0aa4785baf330b1754ba54ed7024959635a1f6bc2557a3a96de70e&scene=126&sessionid=1599533510&key=baed9475c9f7eb8be43db03454ebf97ae40b0b6d2ca233ff353a1d844aae82262c7d9b43975b226cc863c73aab901efb31fa9e52d2abeabaf37446640ac4a74da09d66cb9203dd4f906ebff8aba8291e23ce210292a6eedce9ae86e35f78cf35d4330633526b117f32e1607f55ee5614fe1753e794c4fab9a3ce4b58424d2230&ascene=1&uin=MjIwODk2NDgxNw%3D%3D&devicetype=Windows+10+x64&version=62090529&lang=zh_TW&exportkey=Aib1RsJnvpNMCySGfaXXqnQ%3D&pass_ticket=rViAKoc1EQ9ZP60vV6S60CIjQt0i06M%2BciCMLqNluXpjH6sG6F5QaHbOQsyLYIBK&wx_header=0


1.普通進度條

import sys
import time
def progress_bar():
    for i in range(1, 101):
        print("\r", end="")
        print("Download progress: {}%: ".format(i), "▋" * (i // 2), end="")
        sys.stdout.flush()
        time.sleep(0.05)
progress_bar()


2.帶時間進度條

import time
scale = 50
print("执行开始,祈祷不报错".center(scale // 2,"-"))
start = time.perf_counter()
for i in range(scale + 1):
    a = "*" * i
    b = "." * (scale - i)
    c = (i / scale) * 100
    dur = time.perf_counter() - start
    print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur),end = "")
    time.sleep(0.1)
print("\n"+"执行结束,万幸".center(scale // 2,"-"))


3.tpdm進度條

from time import sleep
from tqdm import tqdm

# 这里同样的,tqdm就是这个进度条最常用的一个方法
# 里面存一个可迭代对象
for i in tqdm(range(1, 500)):
   # 模拟你的任务
   sleep(0.01)
sleep(0.5)


4.progress進度條

import time
from progress.bar import IncrementalBar

mylist = [1,2,3,4,5,6,7,8]
bar = IncrementalBar('Countdown', max = len(mylist))
for item in mylist:
    bar.next()
    time.sleep(1)
    bar.finish()


5.alive_progress進度條

from alive_progress import alive_bar

items = range(100)                  # retrieve your set of items
with alive_bar(len(items)) as bar:   # declare your expected total
    for item in items:               # iterate as usual
        # process each item
        bar()
        time.sleep(0.1)


6.可視化進度條

import PySimpleGUI as sg
import time

mylist = [1,2,3,4,5,6,7,8]
for i, item in enumerate(mylist):
    sg.one_line_progress_meter('This is my progress meter!', i+1, len(mylist), '-key-')
    time.sleep(1)

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *