Tkinter 之ProgressBar進度條標簽


一、參數說明

參數 作用
cursor 鼠標位於進度條內時的形狀
length 進度條長度
maximum 進度條最大刻度值
mode  進度條的模式。有兩種:‘determinate’和’indeterminate’
orient 進度條的方向,有HORIZONTAL 和VERTICAL兩種
style 定義進度條的外觀
takefocus 是否可以通過Tab獲得輸入焦點
variable 與進度條關聯的變量。可以設置或獲得進度條的當前值
value 設置或者獲取進度條的當前值

函數列表:

start(interval=None)

自動調整進度條的位置。通過啟動一個循環定時事件,按照定義的步長調整進度條位置。定時器的間隔由interval參數來設定。間隔單位是毫秒.默認間隔是50毫秒。

step(amount=None)

每次調整進度條的步長,默認是1.0

stop()

停止定時器,停止進度條的自動調整

 

二、代碼示例

import tkinter as tk
from tkinter import ttk

window = tk.Tk()
# 設置窗口大小
winWidth = 600
winHeight = 400
# 獲取屏幕分辨率
screenWidth = window.winfo_screenwidth()
screenHeight = window.winfo_screenheight()

x = int((screenWidth - winWidth) / 2)
y = int((screenHeight - winHeight) / 2)

# 設置主窗口標題
window.title("ProgressBar參數說明")
# 設置窗口初始位置在屏幕居中
window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
# 設置窗口圖標
window.iconbitmap("./image/icon.ico")
# 設置窗口寬高固定
window.resizable(0, 0)

""" Progressbar參數

        STANDARD OPTIONS

            class, cursor, style, takefocus

        WIDGET-SPECIFIC OPTIONS

            orient, length, mode, maximum, value, variable, phase
 """

pb = ttk.Progressbar(window, length = 400, value = 0, mode = "indeterminate")
pb.pack(pady = 10)

def start():
    pb.start()

tk.Button(window, text="開始", command=start).pack()

window.mainloop()

  

三、效果圖

 

 


免責聲明!

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



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