在python tkinter中Canvas实现进度条显示的方法

yipeiwu_com5年前Python基础

如下所示:

from tkinter import *
import time
 
#更新进度条函数
def change_schedule(now_schedule,all_schedule):
 canvas.coords(fill_rec, (5, 5, 6 + (now_schedule/all_schedule)*100, 25))
 root.update()
 x.set(str(round(now_schedule/all_schedule*100,2)) + '%')
 if round(now_schedule/all_schedule*100,2) == 100.00:
  x.set("完成")
 
root = Tk()
#创建画布
frame = Frame(root).grid(row = 0,column = 0)#使用时将框架根据情况选择新的位置
canvas = Canvas(frame,width = 120,height = 30,bg = "white")
canvas.grid(row = 0,column = 0)
x = StringVar()
#进度条以及完成程度
out_rec = canvas.create_rectangle(5,5,105,25,outline = "blue",width = 1)
fill_rec = canvas.create_rectangle(5,5,5,25,outline = "",width = 0,fill = "blue")
 
Label(frame,textvariable = x).grid(row = 0,column = 1)
 
'''
使用时直接调用函数change_schedule(now_schedule,all_schedule)
下面就模拟一下....
'''
 
for i in range(100):
 time.sleep(0.1)
 change_schedule(i,99)
 
mainloop()

实现的甚是粗糙......

以上这篇在python tkinter中Canvas实现进度条显示的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

浅谈python for循环的巧妙运用(迭代、列表生成式)

介绍 我们可以通过for循环来迭代list、tuple、dict、set、字符串,dict比较特殊dict的存储不是连续的,所以迭代(遍历)出来的值的顺序也会发生变化。 迭代(遍历)...

python 设置文件编码格式的实现方法

如果要在python2的py文件里面写中文,则必须要添加一行声明文件编码的注释,否则python2会默认使用ASCII编码。(python3已经没有这个问题了,python3默认的文件编...

windows系统下Python环境的搭建(Aptana Studio)

windows系统下Python环境的搭建(Aptana Studio)

1、首先访问http://www.python.org/download/去下载最新的python版本。 2、安装下载包,一路next。 3、为计算机添加安装目录搭到环境变量,如图...

django 使用 PIL 压缩图片的例子

在最近做项目时,发现服务器上的图片比较大,数据传输时会消耗很多流量,体验非常不好。为了缓解这一现象,决定使用gzip压缩数据流,但是发现gzip对于json数据的压缩效果很好,但对于图片...

python将多个文本文件合并为一个文本的代码(便于搜索)

但是,当一本书学过之后,对一般的技术和函数都有了印象,突然想要查找某个函数的实例代码时,却感到很困难,因为一本书的源代码目录很长,往往有几十甚至上百个源代码文件,想要找到自己想要的函数实...