小编tch*_*haz的帖子

如何将python多处理过程输出发送到Tkinter gui

我正在尝试从Tkinter gui中显示的python多处理过程中获取输出.

我可以通过gui将进程的输出发送到命令shell,例如在shell提示符下运行fllowing tiny脚本:

from multiprocessing import Process  
import sys  

def myfunc(text):    
    print text  
    sys.stdout.flush() 

def f1():  
    p1 = Process(target = myfunc, args = ("Surprise",))  
    p1.start()  

def f2():  
    p2 = Process(target = myfunc, args = ("Fear",))  
    p2.start()  

def fp():  
    myfunc("... and an almost fanatical devotion to the Pope")  

a = Tk()  

b1 = Button(a, text="Process 1", command=f1)  
b1.grid(row=0, column=0, pady=10, padx=10, sticky=SE)  
b2 = Button(a, text="Process 2", command=f2)  
b2.grid(row=0, column=1, pady=10, padx=10, sticky=SE)  
b3 = Button(a, text="Parent", command=fp)  
b3.grid(row=0, column=2, …
Run Code Online (Sandbox Code Playgroud)

python user-interface stdout tkinter multiprocessing

8
推荐指数
1
解决办法
6820
查看次数