Aug-16-2017, 08:41 PM
I create a GUI window by using wx Frame/Panel and make a sample with some dummy code below.
when click on Run button, it will call function_1 with 0 as parameter and get returned result.
function_1 will take 2 minutes to finish but when running, the window will freeze until done.
I'm wondering if possible to run it in anther processor or thread which is different from its parent wx.Frame by using something like multiprocessing or multithreading. so I can still work on the window while function_1 is running. Thanks.
when click on Run button, it will call function_1 with 0 as parameter and get returned result.
function_1 will take 2 minutes to finish but when running, the window will freeze until done.
I'm wondering if possible to run it in anther processor or thread which is different from its parent wx.Frame by using something like multiprocessing or multithreading. so I can still work on the window while function_1 is running. Thanks.
import wx class Frame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, title="Multiprocessing", size=(550, 550), pos = (300, 300)) p = wx.Panel(self) runButton = wx.Button(self, label="Run it", pos=(200, 200)) runButton.Bind(wx.EVT_BUTTON, self.onClick) def onClick(self,event): print('function_1 will run 2 minutes and return result.') # r = function_1(0) # function_2(r) # def function_1(): # ...... # return result if __name__ == "__main__": app = wx.App() win = Frame() win.CreateStatusBar() win.Show() app.MainLoop()