title: Tkinter window does not close if used with matplotlib.pyplot
body: <p>I ran into a problem using <code>tkinter</code> and <code>matplotlib.pyplot</code>, that I don't understand.</p>
  <h2>Minimal example</h2>
  <pre><code>import tkinter
  import tkinter.filedialog as  tk_filedialog
  
  import numpy as np
  import matplotlib.pyplot as plt
  
  def main():
  
      # # -- part 1 --
      # tkinter.Tk().withdraw()
      junk = tk_filedialog.askopenfilename()
  
      # # -- part 2 --
      x_p = np.linspace(0,10,100)
      fig = plt.figure()
      plt.plot(x_p,x_p,color='b')
      plt.show()
  
      print(&quot;blob&quot;)
  
  if __name__ == '__main__':
      main()
  print(&quot;blab&quot;)
  </code></pre>
  <p>My implementation was originally with the line <code>tkinter.Tk().withdraw()</code> uncommented, but then you don't see what happens.</p>
  <p>The program above will run but does not terminate. It should do the following steps:</p>
  <ol>
  <li>Open Tkinter &quot;Select-File-Dialog&quot; -&gt; Choose any file, as it does nothing.</li>
  <li>Plot the curve -&gt; Close the Plot Window</li>
  <li>Print &quot;blob&quot;, print &quot;blab&quot;</li>
  </ol>
  <p>The problem is that the Tkinter window, which would be suppressed by <code>tkinter.Tk().withdraw()</code>, does not close. That leads to two unexpected behaviours - see below.</p>
  <p>The most confusing part is: If you comment either <code>-- part 1 --</code> or <code>-- part 2 --</code> the program will run as expected.</p>
  <hr />
  <h2>Winpython3.5 started from Cygwin</h2>
  <p>After closing this tkinter window &quot;blob&quot; and &quot;blab&quot; will be printed and the program terminates as expected.
  <a href="https://i.stack.imgur.com/7NWrL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7NWrL.png" alt="enter image description here" /></a></p>
  <hr />
  <h2>Spyder 3</h2>
  <p>&quot;blob&quot; and &quot;blab&quot; are printed before closing the figure window, and before closing the tk window.  Additionally it is impossible to close the tk window (the x-button does nothing). It closes with closing spyder, though.
  <a href="https://i.stack.imgur.com/HclC9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HclC9.png" alt="enter image description here" /></a></p>
  <hr />
  <h2>IDLE</h2>
  <p>Same behaviour as Cygwin.</p>
  <hr />
  <p>Any ideas? Did I miss some <code>close()</code> command for tkinter?</p>
  <p>I found this:</p>
  <pre><code>tk_window = tkinter.Tk()
  tk_window.destroy()
  </code></pre>
  <p>But that does not solve the problem above.</p>