Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tkinter多处理:不显示主GUI窗口_Python_Tkinter_Multiprocessing - Fatal编程技术网

Python Tkinter多处理:不显示主GUI窗口

Python Tkinter多处理:不显示主GUI窗口,python,tkinter,multiprocessing,Python,Tkinter,Multiprocessing,我是python新手,尝试用Tkinter实现多进程。我有一个主要的GUI进程,还有两个其他的测试进程。这段代码在Windows中运行良好,显示主窗口,其他两个进程也在运行。但是,当我在Ubuntu中运行此代码时,它不起作用,两个测试进程正在运行,但主GUI窗口没有显示。 有人能帮我吗 from Tkinter import * from multiprocessing import Process import time def mywind(): root=Tk()

我是python新手,尝试用Tkinter实现多进程。我有一个主要的GUI进程,还有两个其他的测试进程。这段代码在Windows中运行良好,显示主窗口,其他两个进程也在运行。但是,当我在Ubuntu中运行此代码时,它不起作用,两个测试进程正在运行,但主GUI窗口没有显示。 有人能帮我吗

from Tkinter import *   
from multiprocessing import Process  
import time
def mywind():
      root=Tk()    
      root.title = "MyWindow"  
      frame=Frame(root)  
      root.mainloop()
def test1():   
    while True:    
        print  "In test1"    
        time.sleep(1)    

def test2():    
    while True:   
        print  "In test2"    
        time.sleep(1)    

if __name__ == '__main__':

    p1 = Process(target=test1)
    p1.start()
    p2 = Process(target=test2)
    p2.start()
    p = Process(target=mywind)
    p.start()
    while True:
        time.sleep(1)
试试这个:

from Tkinter import *
from multiprocessing import Process
import time

root = None

def mywind():
    root=Tk()
    root.title = "MyWindow"
    frame=Frame(root)
    return root

def test1():
    while True:
        print  "In test1"
        time.sleep(1)

def test2():
    while True:
        print  "In test2"
        time.sleep(1)

if __name__ == '__main__':

    p1 = Process(target=test1)
    p1.start()
    p2 = Process(target=test2)
    p2.start()
    root = mywind()
    root.mainloop()
我无法很好地解释为什么将主循环放入主流程而不是子流程是可行的。我认为这与Tk库管理Tk资源和底层本机窗口资源的方式有关,并且与在单独进程中运行它们的想法相冲突。

可能的重复