2 回答
TA贡献1825条经验 获得超4个赞
这奏效了。无需使用检查线程是否已完成。.after()
import os
from tkinter import *
from tkinter.ttk import *
import threading
def use_pyinstaller(): # this function is to execute pyinstaller command and add value to progressbar.
v = 0
for x in files:
os.system('pyinstaller '+x)
v+=1
p['value'] = v
def begin():
threading.Thread(target=use_pyinstaller).start() # create a non-block thread to start the function.
directory = dir_path = os.path.dirname(os.path.realpath(__file__))
files = os.listdir(directory)
root = Tk()
root.geometry('200x200')
root.maxsize(200,200)
root.minsize(200,200)
root.title('PYTOEXE')
p = Progressbar(root,length=200,max=len(files))
b = Button(root,text="Start",command=begin)
p.place(x=0,y=0)
b.place(x=62,y=30)
root.mainloop()
TA贡献1891条经验 获得超3个赞
首先,按钮的参数可以只是:。commandcommand=begin
GUI 工具包(如)是事件驱动的。它们依赖于键盘和鼠标事件的顺畅流动才能正常工作。回调(如来自按钮)是从事件循环 () 调用的。因此,回调应该只需要很短的时间(例如50毫秒)才能不冻结GUI。因此,切勿在回调中运行长时间运行的循环。你必须以不同的风格编程。tkintercommandroot.mainloop
上面的链接将您带到我网站上的一篇文章,我将简单的命令行程序与等效的GUI程序进行了比较。虽然该程序不使用外部进程,但它说明了原理。
在 GUI 中执行此操作的正确方法是从按钮回调开始 。然后使用该方法定期运行检查 是否已完成的回调,然后启动新进程。multiprocessing.Processroot.afterProcess
添加回答
举报
