在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动态监控日志内容的示例

日志文件一般是按天产生,则通过在程序中判断文件的产生日期与当前时间,更换监控的日志文件程序只是简单的示例一下,监控test1.log 10秒,转向监控test2.log 程序监控使用是l...

pytorch 数据处理:定义自己的数据集合实例

数据处理 版本1 #数据处理 import os import torch from torch.utils import data from PIL import Image im...

对Python 2.7 pandas 中的read_excel详解

导入pandas模块: import pandas as pd 使用import读入pandas模块,并且为了方便使用其缩写pd指代。 读入待处理的excel文件: df =...

Python导出DBF文件到Excel的方法

本文实例讲述了Python导出DBF文件到Excel的方法。分享给大家供大家参考。具体如下: from dbfpy import dbf from time import sleep...

python编写的最短路径算法

python编写的最短路径算法

一心想学习算法,很少去真正静下心来去研究,前几天趁着周末去了解了最短路径的资料,用python写了一个最短路径算法。算法是基于带权无向图去寻找两个点之间的最短路径,数据存储用邻接矩阵记录...