Why the GUI is not show, but the child process is start?

hi, all
Why the GUI is not show, but the child process is start? My code is like below:

app = wx.App(None)
frame = MainWindow()
p = Process(target=WorkerThread)
p.start()
frame.SetSize(470,420)
frame.Show()
app.MainLoop()

Please create a complete, small, runnable sample so it’s easier for others to help diagnose your problem.

import multiprocessing
import os, wx, time, winput

class WorkerThread():
    def __init__(self):
        Thread.__init__(self)
    def mouse_callback( event ):
        if event.action == winput.WM_LBUTTONDOWN:
            print("Left mouse button press at {}".format( event.position ))
        
    def keyboard_callback( event ):
        if event.vkCode == winput.VK_ESCAPE: # quit on pressing escape
            winput.stop()
            
    print("Press escape to quit")
        
    # hook input    
    winput.hook_mouse( mouse_callback )
    winput.hook_keyboard( keyboard_callback )

    # enter message loop
    try:
        while 1:
            time.sleep(1./120)
            msg = (winput.get_message())
            if msg:
                break
    except KeyboardInterrupt:
        pass

    # remove input hook
    winput.unhook_mouse()
    winput.unhook_keyboard()

class MainWindow(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="sylphlker按键精灵", 
            style=wx.DEFAULT_FRAME_STYLE^wx.RESIZE_BORDER^wx.MAXIMIZE_BOX)
        self.Center()
        self.panel = wx.Panel(self, wx.ID_ANY)            


        #控件制作
        self.c1  = wx.CheckBox(self.panel, -1, label="", style=0)


if __name__ == '__main__':
    freeze.support()
    app = wx.App(None)   
    frame = MainWindow()
    p = Process(target=WorkerThread)
    p.start()
    frame.SetSize(470,420)
    frame.Show()
    app.MainLoop()

Maybe there are some bugs of the ‘winput’ module? It looks like very few people use it.

Inside your WorkerThread you have a bunch of stuff at class scope that should probably be inside of a run method. So what happens is as Python is parsing that code and creating the class object it executes the code from the print("Press escape... line to the end of the class at that moment of time. It hasn’t even gotten to the code in the if __name__ ... block yet and you have it waiting in a message loop until the ESC is pressed. Then after the ESC if finally gets to the block at the end and runs into a NameError exception because there is no known freeze.support()

Or perhaps you intended WorkerThread to be a function, not a class.