progressbar:python进度条功能

jupiter
2021-01-14 / 0 评论 / 719 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年01月13日,已超过834天没有更新,若内容或图片失效,请留言反馈。

1.安装

progressbar安装:

pip install progressbar

2.使用

2.1 用法一

import time
from progressbar import *
 
total = 1000
 
def dosomework():
    time.sleep(0.01)
 
progress = ProgressBar()
for i in progress(range(1000)):
    dosomework()
  • 用法一显示效果
5% |###                                                                      |
100% |#########################################################################|

2.2 用法二

import time
from progressbar import *
 
total = 1000
 
def dosomework():
    time.sleep(0.01)

pbar = ProgressBar().start()
for i in range(1000):
    pbar.update(int((i / (total - 1)) * 100))
    dosomework()
pbar.finish()
  • 用法二显示效果
5% |###                                                                      |
100% |#########################################################################|

2.3 用法三

import  time
from progressbar import *
 
total = 1000
 
def dosomework():
    time.sleep(0.01)
 
widgets = ['Progress: ',Percentage(), ' ', Bar('#'),' ', Timer(),' ', ETA(), ' ', FileTransferSpeed()]
pbar = ProgressBar(widgets=widgets, maxval=10*total).start()
for i in range(total):
    # do something
    pbar.update(10 * i + 1)
    dosomework()
pbar.finish()
widgets可选参数含义:
Progress: ' :设置进度条前显示的文字
Percentage() :显示百分比
Bar('#') : 设置进度条形状
Timer() :显示已用时间
ETA() : 显示预计剩余时间
  • 用法三显示效果
Progress: 100% |#############| Elapsed Time: 0:00:10  Time: 0:00:10 981.79  B/s
0

评论 (0)

打卡
取消