大家好,我正在使用python 2.7.15和tkinter。这是一个带有一些按钮的简单GUI。一旦按下按钮,我需要在线程中启动一个函数(我不需要打开任何新窗口)。
对于每个线程,都会打开程序的一个新GUI副本。有没有办法在不弹出Tkinter gui的新副本的情况下启动一个函数(进行一些计算)?
我正在做一条这样的线:
thread = Process(target=functionName, args=(arg1, arg2))
thread.start()
thread.join()
编辑:这里有一些代码可以复制。正如你们所看到的,我对下面的“示例”感兴趣的是运行一个函数。而不是克隆整个程序。
from Tkinter import *
from multiprocessing import Process
window = Tk()
window.title("Test threadinng")
window.geometry('400x400')
def threadFunction():
sys.exit()
def start():
thread1 = Process(target=threadFunction)
thread2 = Process(target=threadFunction)
thread1.start()
thread2.start()
thread1.join()
thread2.join()
btn = Button(window, text="Click Me", command=start, args=())
btn.grid(column=1, row=1)
window.mainloop()
非常感谢。