[转载]tkinter的canvas画进度条的实例

仅作为记录,大佬请跳过。

转载的所有程序

可以直接运行

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()

展示

在这里插入图片描述

参考

感谢大佬博主文章:传送门

尝试

在invatool_selfpoints.py文件里的load_img()re_load_img(),加入:

    # 进度条设计
    out_rec = canvas.create_rectangle(0, 256*3+5, 256*3, 256*3+15, outline="blue", width=1)
    fill_rec = canvas.create_rectangle(0, 256*3+5, 0, 256*3+15, outline="", width=0, fill="blue")
    all_schedule = len(imgs)
    now_schedule=len(pd.read_csv('label_selfpoints.csv', encoding="utf-8"))
    # now_schedule=0      # 设计获取csv图像个数的函数-reload也写进度条设计程序-加入16/17
    canvas.coords(fill_rec, (0, 256*3+5, 1 + (now_schedule / all_schedule) * 256*3, 256*3+15))
    root.update()

在这里插入图片描述
展示

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值