我试图在 for 循环上显示进度条,for 循环有效但进程条不前进,只显示窗口但它冻结了。进程定时结束,窗口静止
这是我到目前为止所得到的,我尝试使用 tkinter 类,但它做了同样的事情。当我使用按钮内的功能启动流程时,它会起作用,但这不适用于我尝试执行的整个流程。
事情是这样的:
这是我测试进度条的代码:
from tkinter import *
from tkinter.ttk import *
import time
# Waiting screen, start button
root = Tk()
var = IntVar()
button = Button(root, text="Start", command=lambda: var.set(1))
button.pack()
print("waiting...")
button.wait_variable(var)
print("done waiting.")
# Creation of progress bar
total = 100
root = Tk()
progress = Progressbar(root, length=400, mode='determinate')
label = Label(root, text=f'Processing {total} files').pack()
progress.pack()
c = 0
for i in range(total):
time.sleep(.1)
print(i) # Several functions nested in loop
c += 1
progress['value'] = c
root.update_idletasks()
if c == total:
root.destroy()
progress.pack()
root.mainloop()