首页 技术 正文
技术 2022年11月20日
0 收藏 463 点赞 4,694 浏览 2482 个字
 import sys,time
#导入模块 for i in range(50):
#进度条的长度
sys.stdout.write("#")
#进度条的内容,这里要注意了,pycharm有可能不显示write的方法
sys.stdout.flush()
#刷新缓存
time.sleep(0.5)
#间隔时间,和shell的sleep差不多吧

或者

import sysclass progressbar(object):    def __init__(self, finalcount, block_char='.'):
self.finalcount = finalcount
self.blockcount = 0
self.block = block_char
self.f = sys.stdout
if not self.finalcount:
return
self.f.write('\n------------------ % Progress -------------------1\n')
self.f.write(' 1 2 3 4 5 6 7 8 9 0\n')
self.f.write('----0----0----0----0----0----0----0----0----0----0\n') def progress(self, count):
count = min(count, self.finalcount)
if self.finalcount:
percentcomplete = int(round(100.0 * count / self.finalcount))
if percentcomplete < 1:
percentcomplete = 1
else:
percentcomplete = 100
blockcount = int(percentcomplete // 2)
if blockcount <= self.blockcount:
return
for i in range(self.blockcount, blockcount):
self.f.write(self.block)
self.f.flush()
self.blockcount = blockcount
if percentcomplete == 100:
self.f.write("\n")if __name__ == "__main__":
from time import sleep
pb = progressbar(8, "*")
for count in range(1, 9):
pb.progress(count)
sleep(0.2)
pb = progressbar(100)
pb.progress(20)
sleep(0.3)
pb.progress(47)
sleep(0.3)
pb.progress(90)
sleep(0.3)
pb.progress(100)
print "testing 1:"
pb = progressbar(1)
pb.progress(1)

或者:

# -*- coding: UTF-8 -*-import sys, timeclass ShowProcess():
"""
显示处理进度的类
调用该类相关函数即可实现处理进度的显示
"""
i = 0 # 当前的处理进度
max_steps = 0 # 总共需要处理的次数
max_arrow = 50 #进度条的长度 # 初始化函数,需要知道总共的处理次数
def __init__(self, max_steps):
self.max_steps = max_steps
self.i = 0 # 显示函数,根据当前的处理进度i显示进度
# 效果为[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]100.00%
def show_process(self, i=None):
if i is not None:
self.i = i
else:
self.i += 1
num_arrow = int(self.i * self.max_arrow / self.max_steps) #计算显示多少个'>'
num_line = self.max_arrow - num_arrow #计算显示多少个'-'
percent = self.i * 100.0 / self.max_steps #计算完成进度,格式为xx.xx%
process_bar = '[' + '>' * num_arrow + '-' * num_line + ']'\
+ '%.2f' % percent + '%' + '\r' #带输出的字符串,'\r'表示不换行回到最左边
sys.stdout.write(process_bar) #这两句打印字符到终端
sys.stdout.flush() def close(self, words='done'):
print ''
print words
self.i = 0if __name__=='__main__':
max_steps = 100 process_bar = ShowProcess(max_steps) for i in range(max_steps + 1):
process_bar.show_process()
time.sleep(0.05)
process_bar.close()

或者:

from Tkinter import *def resize(ev=None):
label.config(font='Helvetica -%d bold' % scale.get())top = Tk()
top.geometry()label = Label(top, text = 'hello world!', font = 'Helvetica -12 bold')
label.pack(fill=Y,expand=1)scale = Scale(top, from_=10, to=40, orient=HORIZONTAL, command=resize)
scale.set(12)
scale.pack(fill=X, expand=1)quit = Button(top, text="QUIT", command=top.quit, activeforeground='white', activebackground='red')
quit.pack()mainloop()
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,983
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,500
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,344
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,127
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,761
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,838