Python使用progressbar模块实现的显示进度条功能
作者:-牧野- 时间:2023-11-20 05:40:07
本文实例讲述了Python使用progressbar模块实现的显示进度条功能。分享给大家供大家参考,具体如下:
progressbar安装:
pip install progressbar
用法一
# -*- coding=utf-8 -*-
import time
from progressbar import *
total = 1000
def dosomework():
time.sleep(0.01)
progress = ProgressBar()
for i in progress(range(1000)):
dosomework()
显示效果:
5% |### |
100% |#########################################################################|
用法二
# -*- coding=utf-8 -*-
from __future__ import division
import sys, 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()
显示效果:
39% |############################## |
100% |#############################################################################|
用法三
# -*- coding=utf-8 -*-
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()
显示效果:
Progress: 3% |### | Elapsed Time: 0:00:15 ETA: 0:09:02 919.67 B/s
Progress: 100% |###################################################################################| Elapsed Time: 0:10:10 Time: 0:10:10 917.42 B/s
widgets可选参数含义:
'Progress: ' :设置进度条前显示的文字
Percentage() :显示百分比
Bar('#') : 设置进度条形状
ETA() : 显示预计剩余时间
Timer() :显示已用时间
希望本文所述对大家Python程序设计有所帮助。
来源:https://blog.csdn.net/dcrmg/article/details/79525167
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python中map,reduce,filter和sorted函数的使用方法
100行Python代码实现自动抢火车票(附源码)
![](https://img.aspxhome.com/file/2023/7/91957_0s.jpg)
PyCharm代码格式调整方法
Javascript 注册事件浅析
PHP函数之error_reporting(E_ALL ^ E_NOTICE)详细说明
Django {{ MEDIA_URL }}无法显示图片的解决方式
用css制作星级投票评分功能
![](https://img.aspxhome.com/file/UploadPic/20071/2007131101422899s.gif)
SQL Server Table中XML列的操作代码
sql 语句 取数据库服务器上所有数据库的名字
聊聊Python代码中if __name__ == ‘__main__‘的作用是什么
![](https://img.aspxhome.com/file/2023/6/118606_0s.jpg)
python中的load、loads实现反序列化示列
利用Python实现Picgo图床工具
一文带你看懂Vue Hook和React Hook
解决Extjs下拉框不显示的问题
![](https://img.aspxhome.com/file/2023/9/135629_0s.png)
Blender Python编程实现程序化建模生成超形示例详解
![](https://img.aspxhome.com/file/2023/8/128518_0s.png)
Django Paginator分页器的使用示例
![](https://img.aspxhome.com/file/2023/4/127904_0s.png)
python 剪切移动文件的实现代码
Python基础必备之语法结构详解
![](https://img.aspxhome.com/file/2023/2/90712_0s.jpg)
vue axios二次封装的详细解析
![](https://img.aspxhome.com/file/2023/6/129926_0s.png)