title: %gui tk followed by a traceback hangs the Jupyter kernel, looking for a fix or workaround
body: <p>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 <code>%gui tk</code> for the GUI to show up, and that I shouldn't call <code>mainloop()</code> on my root if I want to continue evaluating Jupyter cells.</p>
  <p>The problem is the side effect on Jupyter. The example pictured below is the simplest that reproduces the problem for me.  If I wait &quot;long enough&quot; after the <code>gui %tk</code> 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 &quot;[ ]&quot; 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 <code>%gui tk</code> and the Kernel interrupt, as long as no tracebacks occur.</p>
  <p><a href="https://i.stack.imgur.com/siOQA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/siOQA.png" alt="Example of state after traceback" /></a></p>
  <p>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.</p>
  <p>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 <code>%gui qt</code> and it doesn't have that effect)  but since tkinter is what I'm currently used to and since it comes &quot;standard&quot; with Python I would hope that it can be made to work.</p>
  <p>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):</p>
  <ul>
  <li>python 3.8.8</li>
  <li>tk 8.6.10</li>
  <li>jupyter 1.1.0</li>
  <li>jupyter_core 4.7.1</li>
  <li>jupyter_server 1.4.1</li>
  <li>jupyter_client 6.1.12</li>
  </ul>