在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设计】。

相关文章

老生常谈Python startswith()函数与endswith函数

函数:startswith() 作用:判断字符串是否以指定字符或子字符串开头 一、函数说明 语法:string.startswith(str, beg=0,end=len(string)...

Python contextlib模块使用示例

看这个模块要先看with as的用法,最常用的方法就是打开一个文件: 复制代码 代码如下: with open(“filename”) as f: f.read() with可以调用一...

详细介绍Python的鸭子类型

鸭子类型基本定义 首先Python不支持多态,也不用支持多态,python是一种多态语言,崇尚鸭子类型。 以下是维基百科中对鸭子类型得论述: 在程序设计中,鸭子类型(英语:duck t...

Django 对象关系映射(ORM)源码详解

前言 从前面已经知道, 一个 request 的到来和一个对应 response 的返回的流程, 数据处理和数据库离不开. 我们也经常在 views.py 的函数定义中与数据库打交道....

Python时间序列处理之ARIMA模型的使用讲解

Python时间序列处理之ARIMA模型的使用讲解

ARIMA模型 ARIMA模型的全称是自回归移动平均模型,是用来预测时间序列的一种常用的统计模型,一般记作ARIMA(p,d,q)。 ARIMA的适应情况 ARIMA模型相对来说比较简单...