1
運行tkinter的函數會凍結。 我想使用運行該進程的Tkinter窗口。在運行進度條 我想使用tkinter window.but但我不能 ,因爲它凍結tkinter。 如何使用根窗口,而time.sleep(10)或其他功能工作如何在tkinter中使用作品
import tkinter.ttk as ttk
import tkinter as tk
import time
progress = 0
def loading(window=None):
mpb = ttk.Progressbar(window, orient="horizontal", length=200, mode="determinate")
mpb.place(y=0, x=0)
mpb["maximum"] = 100
mpb["value"] = progress
print(progress)
def incrase():
global progress
print(progress)
progress += 1
time.sleep(10) # for example, a function works here and tkinter freezes
loading() # i don't want tkinter freezes
root = tk.Tk()
loading(root)
ttk.Button(root, text='increase', command=incrase).place(x=0, y=25, width=90)
root.mainloop()
感謝答案