I am trying to use tkinter from Jupyter. I actually have no problem making my tkinter GUI work (I found out that I need the magic command %gui tk for the GUI to show up, and that I shouldn't call mainloop() on my root if I want to continue evaluating Jupyter cells.
The problem is the side effect on Jupyter. The example pictured below is the simplest that reproduces the problem for me. If I wait "long enough" after the gui %tk line, then the first time I try to execute the second cell (0/0), the kernel gets stuck in the '[*]' state. I can get out of that by interrupting the Kernel and executing the cell again. At that point I get the traceback as expected. The big problem is that when I try to execute the third cell, the kernel seems to have completely given up. The cell status stays stuck in the "[ ]" state, and interrupting the Kernel does not allow me to continue this time. I have to restart the Kernel for things to work again. Note that in this particular example, I haven't instantiated any tkinter objects; the magic command alone causes the problem. In all other instances where the problem occurs, the triggering event is a traceback. I can execute as many cells as I want after the %gui tk and the Kernel interrupt, as long as no tracebacks occur.
If I execute all cells in quick succession then the problems do not occur, but they eventually occur soon after when I try to execute other cells. I search the Internet but I didn't find anyone with a similar problem.
I do not want to use ipywidgets because I need the GUI to be handily available (not requiring to scroll through the notebook to find). I suppose I could try other GUIs (I tried %gui qt and it doesn't have that effect) but since tkinter is what I'm currently used to and since it comes "standard" with Python I would hope that it can be made to work.
I'm using an Anaconda distribution (3-2121.05-Windows-x86_64). Here are a few version numbers (if more would be useful, let me know):
- python 3.8.8
- tk 8.6.10
- jupyter 1.1.0
- jupyter_core 4.7.1
- jupyter_server 1.4.1
- jupyter_client 6.1.12
