Using python 2 or 3, matplotlib and tkinter causes an extra empty window to open on calling plt.show()
<p>I am making an interactive data analysis tool that I am having trouble with (in <code>python 2.7</code>, <code>3.4</code> and <code>3.5</code>). The full program makes graphs that the user has to interact with and then close. It also requires the user to input files via a filechooser. </p>

<p>The issue is whenever I use <code>plt.show()</code> an additional small window opens (which I don't want) along with the graph. The small window then has to be closed too, to continue the program. Not that big a deal, but there are many graphs to interact with, so it is a bit off a pain always closing two windows.</p>

<p>If the <code>Tkinter.Tk().withraw()</code> is uncommented only the plot opens, but now the program just hangs upon closing the graph and I have to kill the process. </p>

<p>Any ideas for how I might get around this problem?</p>

<p>Thanks in advance. Example code:</p>

<pre><code>import matplotlib.pyplot as plt
import numpy as np
try:
    import Tkinter
except (ImportError):
    import tkinter as Tkinter
try:
    from tkFileDialog import askopenfilename
except (ImportError):
    from tkinter.filedialog import askopenfilename

# Tkinter.Tk().withdraw()

print(askopenfilename())


x = np.arange(0,5,0.1)
y = np.sin(x)

plt.plot(x,y)
plt.show()
</code></pre>

<p>You could try naming the figure as maybe it's getting confused as to what you are referring to when you ask it to show a figure</p>

<pre><code>x = np.arange(0,5,0.1)
y = np.sin(x)

fig1 = plt.figure()
plt.plot(x,y)
plt.show(fig1)
</code></pre>

python python-3.x matplotlib tkinter