3.5 python文本进度条举一反三:渐变进度条

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# textbar.py
# 渐变显示进度条
import time
scale = 50
print("执行开始".center(scale//2, "-"))  # str.center(width, fillchar)宽度和填充字符
start = time.perf_counter() # 计时
for i in range(scale+1):
    p = i / scale
    power = (p + (1 - p)/2) ** 8  #函数 进度条设计
    c = power * 100
    a = '*' * int(c)
    b = '.' * (scale - int(c))
    dur = time.perf_counter() - start
    print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c, a, b, dur), end="") # ^数字居中符号 3.2前面是整数保留位数,后面是小数
    time.sleep(0.1)
print("\n"+"执行结束".center(scale//2, "-"))
Licensed under CC BY-NC-SA 4.0
© ziyue.tech版权所有
Built with Hugo
主题 OoO落墨灼夭 设计

本站访问量:   您是本站第 位访问者