如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
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实现进度条显示的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/li1615882553/article/details/79204072