Search code examples
pythonwxpython

How can I close the active window but still run the rest of the execution statements in the function?


I have a function that needs to work between two different windows. It starts off working in one active window. I want it to work with that window until I call

self.Close(true)

This will successfully close the active window, but as far as I understand it, it also terminates any more execution statements I have inside the function. The execution statements that are after the Close call (and still in the same function) are ones I want to be applied to the newly active window.

How can I achieve this? Is there something other than Close I can call?


Solution

  • The usual way to go about this is to have a main wxPython program (i.e. a main window). When you call the long running process, you can hide the main window by calling the frame's Hide() method. When the long running process finishes, you can re-show the main window or you could instantiate a secondary frame and show that while keeping the main window hidden. The secondary frame can show the output from the long running process.

    Another approach would be to hide the main frame during the long running process and then when the process finishes, you just update the main frame and re-show it. You could create a completely different panel for the frame and swap it out for the original to make it look like a completely different frame. This tutorial talks about doing this latter suggestion.