ttk Progressbar只在进程结束时显示

ttk Progressbar display only in the end of the process

根据对象,进度条仅在 for 循环结束时显示。相反,我希望它逐步显示循环的进度。

from tkinter import ttk
from tkinter import *
import time

def inner_loop_func():
    k = 0
    for i in range(10**5):
        k=k+1
    print("k: ",k)

def loop_fun():

    p = ttk.Progressbar(root, orient="horizontal", length=300, mode="determinate", takefocus=True, maximum=100)
    p['value'] = 0
    p.pack()

    end = 100
    for i in range(end):
        start(end,p)
        inner_loop_func()
        print(i," of ", end)

def start(end,p):

    if p['value'] < 300:
        p['value'] += (300/end)
    else:
        print("finish")

if __name__ == "__main__":

    root = Tk()
    loop_fun()
    root.mainloop()

在 loop_fun 函数内使用 p.update() 循环:

for i in range(end):
    start(end, p)
    inner_loop_func()
    print(i, " of ", end)
    p.update()