'Integrating wxPython and Jupyterlab correctly

I'm looking to write wx code within a Jupyterlab notebook. I found a solution here, but it exhibits unusual behavior.

If I run each line separately, it works (can't post image due to new account - follow link).

image of correctly running code

However, if I restart the Kernel and run the file as a whole, no wx App is created and the whole thing crashes. wx.GetApp() returns None.

image of identical code, not working

Why the disparate behavior, and what could be done to work around it?

TIA,



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source