博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python使用progressbar显示进度条
阅读量:4317 次
发布时间:2019-06-06

本文共 1677 字,大约阅读时间需要 5 分钟。

progressbar安装:

pip install progressbar

用法一

# -*- coding=utf-8 -*-import timefrom progressbar import *total = 1000def dosomework():    time.sleep(0.01)progress = ProgressBar()for i in progress(range(1000)):    dosomework()

显示效果:

5% |###                                                                      |100% |#########################################################################|

用法二

# -*- coding=utf-8 -*-from __future__ import divisionimport sys, timefrom progressbar import *total = 1000def 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  timefrom progressbar import *total = 1000def 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/sProgress: 100% |###################################################################################| Elapsed Time: 0:10:10 Time: 0:10:10 917.42  B/s

widgets可选参数含义:

  • 'Progress: ' :设置进度条前显示的文字
  • Percentage() :显示百分比
  • Bar('#') : 设置进度条形状
  • ETA() : 显示预计剩余时间
  • Timer() :显示已用时间

转载于:https://www.cnblogs.com/mtcnn/p/9411731.html

你可能感兴趣的文章
C# - XML
查看>>
android权限大全
查看>>
BZOJ.3262.陌上花开([模板]CDQ分治 三维偏序)
查看>>
[原]unity5 AssetBundle 加载
查看>>
[Day15]常用API(Object类、String类)
查看>>
[置顶] 各种流行的编程风格
查看>>
codeforces1029 E.Tree with Small Distances
查看>>
JavaScript——JS上下文中的this值笔记
查看>>
Bootstrap简单使用
查看>>
导航控制器的出栈
查看>>
玩转CSS3,嗨翻WEB前端,CSS3伪类元素详解/深入浅出[原创][5+3时代]
查看>>
iOS 9音频应用播放音频之播放控制暂停停止前进后退的设置
查看>>
Delphi消息小记
查看>>
HNOI2016
查看>>
BZOJ2648: SJY摆棋子&&2716: [Violet 3]天使玩偶
查看>>
JVM介绍
查看>>
结构体,联合体,内存分配
查看>>
JVM垃圾收集器介绍
查看>>
[No0000136]6个重要的.NET概念:栈,堆,值类型,引用类型,装箱,拆箱
查看>>
【转】MapReduce源码分析总结
查看>>