如下所示:
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實現進度條顯示的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
