tkinter進度條實現


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM