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

  

三、效果图

猜你喜欢

转载自www.cnblogs.com/yang-2018/p/11839104.html