Tkinter/matplotlib multiple active windows on osx
<p>I have a script as follows that executes on my windows machine</p>

<pre><code>import matplotlib.pyplot as plt
import numpy as np
import tkinter

class main(tkinter.Frame): #main window
    def __init__(self, root): # initialise
        tkinter.Frame.__init__(self)
        self.root = root


        tkinter.Button(self, text='New spots', command=self.newSpots).grid()

    def newSpots(self):
        x = np.random.rand(10)
        y = np.random.rand(10)
        plt.scatter(x,y)
        plt.show()



if __name__=='__main__':
    root = tkinter.Tk()

    app = main(root).grid()
    root.mainloop()
</code></pre>

<p>When running on windows, it opens a window with a simple button, and clicking this button opens a matplotlib viewer with 10 dots plotted in random positions. Each subsequent press of the button adds a further ten dots.</p>

<p>Executing this code on a mac produces the same initial window, and the first press of the button generates the plot and opens the viewer as expected. However, it then becomes impossible to interact with the original window (only the controls on the viewer work) until the viewer window is closed. How do I make the behaviour on the mac mirror that on the windows machine?</p>

<p>I found a solution to this issue -- it seems matplotlib defaults to the TkAgg backend on Windows (I'm unsure whether this is a general Windows thing, or specific to whatever particular install is on the machine).</p>

<p>Adding the following lines to the top of the script forces the TkAgg backend and leads to the same behaviour on both machines.</p>

<pre><code>import matplotlib
matplotlib.use("TkAgg")
</code></pre>

python windows osx matplotlib tkinter