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

yipeiwu_com6年前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设计】。

相关文章

Gauss-Seidel迭代算法的Python实现详解

import numpy as np import time 1.1 Gauss-Seidel迭代算法 def GaussSeidel_tensor_V2(A,b,Delta,...

Python 实现顺序高斯消元法示例

Python 实现顺序高斯消元法示例

我就废话不多说,直接上代码吧! # coding: utf8 import numpy as np # 设置矩阵 def getInput(): matrix_a = np.m...

Python正则表达式匹配ip地址实例

本文实例讲述了正则表达式匹配ip地址实例。代码结构非常简单易懂。分享给大家供大家参考。 主要实现代码如下: import re reip = re.compile(r'(?&...

spyder常用快捷键(分享)

最近在学习tensorflow框架,在ubuntu下用到python的一个ide --spyder,以下是常用快捷键 Ctrl+1:注释/撤销注释 Ctrl+4/5:块注释/撤销块注释...

对python append 与浅拷贝的实例讲解

在做Leetcode的第39题的时候,看到网上一个用递归的解法,很简洁。于是重写了一遍。 class Solution(object): def combinationSum(se...