自定义进度条

1.自定义的进度条,拿去用

# 自己写一个进度条
import time
def progress(count,counts,length=50,key="",second=0.1):
    """
    :param count:  已完成的值
    :param counts: 总量
    :param length: 默认字符串长度
    :param key: 进度条字符
    :param second: 刷新间隔
    :return:
    """
    if count <= counts:
        count_str = int(count / counts * length) * key
        count_str = count_str.ljust(length, " ")
        percentage = round(count / counts * 100, 2)
        s = f"[{count_str}] {percentage}% | {round(count, 2)}/{round(counts, 2)}"
        print(f"\r{s}", end="")
        time.sleep(second)
        if percentage == 100:
            print()
    else:
        progress(counts,counts)


if __name__ == "__main__":
    count = 0
    counts = 30
    while True:
        count += 0.3
        progress(count,counts)
        if count>counts:
            break
View Code

 

 

posted @ 2021-09-28 22:27    阅读(41)  评论(0编辑  收藏  举报