python - Tkinter/matplotlib multiple active windows on osx -
i have script follows executes on windows machine
import matplotlib.pyplot plt import numpy 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()
when running on windows, opens window simple button, , clicking button opens matplotlib viewer 10 dots plotted in random positions. each subsequent press of button adds further ten dots.
executing code on mac produces same initial window, , first press of button generates plot , opens viewer expected. however, becomes impossible interact original window (only controls on viewer work) until viewer window closed. how make behaviour on mac mirror on windows machine?
i found solution issue -- seems matplotlib defaults tkagg backend on windows (i'm unsure whether general windows thing, or specific whatever particular install on machine).
adding following lines top of script forces tkagg backend , leads same behaviour on both machines.
import matplotlib matplotlib.use("tkagg")
Comments
Post a Comment