On 08/21/2011 05:54 AM, CAB wrote:
Hi, All,
Sorry if this complaint appears twice on this list.
I have been using Matplotlib for a while, and I'm getting to the point
where I'd like to embed the output in a Tk GUI application. I'm new to
Tkinter. Here is the problem. Using the script that's in the "examples"
page on the web documentation, I run "embedding_in_tk.py". That works.
But if I uncomment the Tkinter-style "Quit" button that is at the bottom
of this script, any attempt to quit using the Quit button causes the
following error:
Fatal Python Error: PyEval_RestoreThread: NULL tstate
That's probably why the button was commented out. I think the problem
here is that using these gui toolkits is tricky, and the tk examples
were never worked out adequately. There are various ways of putting a
quit button back into the example. Try the one attached. If it works
for you, I will make it replace the present example, and I will delete
the embedding_in_tk2.py example because it adds nothing of interest.
Eric
I am using clean installs of Python 2.7, numpy 1.6.1, and matplotlib
1.0.1 (all 32-bit versions running under a Win 7 64-bit OS). I have not
modified the matplotlibrc. Given that this is not working "out of the
box", I'm wondering if there is a bug in FigureCanvasTkAgg or the tkagg
backend in general.
A look at the archives shows a user named Jakob having a similar
problem, but the solution (if any) was not posted.
Any help on this front is appreciated.
Chad
------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
user administration capabilities and model configuration. Take
the hassle out of deploying and managing Subversion and the
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
#!/usr/bin/env python
import matplotlib
matplotlib.use('TkAgg')
from numpy import arange, sin, pi
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import Tkinter as Tk
import sys
root = Tk.Tk()
root.wm_title("Embedding in TK")
f = Figure(figsize=(5,4), dpi=100)
a = f.add_subplot(111)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)
a.plot(t,s)
# a tk.DrawingArea
canvas = FigureCanvasTkAgg(f, master=root)
canvas.show()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
toolbar = NavigationToolbar2TkAgg( canvas, root )
toolbar.update()
canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
def _quit():
root.quit() # stops mainloop
root.destroy() # this is necessary on Windows to prevent
# Fatal Python Error: PyEval_RestoreThread: NULL tstate
button = Tk.Button(master=root, text='Quit', command=_quit)
button.pack(side=Tk.BOTTOM)
Tk.mainloop()
# If you put root.destroy() here, it will cause an error if
# the window is closed with the window manager.
------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
user administration capabilities and model configuration. Take
the hassle out of deploying and managing Subversion and the
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users