I have a module that calls another module where I initialize a canvas with tkinter and a button. When the user clicks on the button it launches a function from the first module. However this function is long and I don't want to have tkinter frozen until the function is completely executed. It seems that multiprocessing would be the solution but I have some difficulties implementing it.
In the first module:
tkinterModule.initialize(functionFromMainModule)
In the second module:
...
button = Button(master,
text="Launch Function",
command=partial(play, callback))
def play(callback=None):
if callback is not None:
callback()
Then in the first module:
def functionFromMainModule():
....
if __name__ == '__main__':
p = multiprocessing.Process(target=longFunction)
p.start()
def longFunction():
...
But instead of launching longFunction it just reinitializes a new tkinter canvas and doesn't start the function. If I just call the function and don't use multiprocessing the function is called normally (but tkinter is frozen until the end of execution).