No, it is not possible. GUI widgets cannot be shared between processes. On some platforms, it just isn't possible at all; on other platforms, it would be possible, but only by doing things very differently from the way Tk does; on others, it sort of works, but the event loops are all screwed up. So, the result may be that nothing shows up, that one or both processes freezes, that the GUI doesn't respond to events, that tkinter raises an exception in the child, that tkinter creates a whole separate independent GUI, or, if you're really unlucky, that things unpredictably work sometimes but do one of the other things other times.
However, that doesn't mean there's no way to do what you want, just that you can't do it directly.
The simplest solution is to marshal your Canvas
commands and pass them over a Pipe
or Queue
for the main process to execute.
A fully general solution isn't that hard, but in your case, it should be even simpler: all you want the background process to do is process an image and then display it. So the only Canvas
command you need is create_image
.
And, in fact, you can probably do with tasks on a Pool
, which just return
the image when they're done, with the main process doing the create_image
with the results.
Mixing waiting on multiprocessing
async results with a tkinter event loop is a bit of a pain, but if you use concurrent.futures
, you can just attach the create_image
as a callback on the Future
returned by the task.
A different option is to have the background processes create off-screen Canvas
objects, draw to them, then capture the results as a BitmapImage
or a postscript
rendering, which you can then pass to the main process to blit onto a Canvas
of its own. But this is a lot more complicated; I think the other solution will probably work a lot better for you.