Well I realized my error with the extra window being caused by the TopLevel() command. I switched this to Tk.Tk() and it works nicely. However I still have to pack the frame instead of using grid. I can work around this but I wonder if there isn't something else I'm missing.
On Tue, Mar 23, 2010 at 6:00 PM, Jonno <jonnojohn...@gmail.com> wrote: > I've been trying to modify the embedding_in_tk.py example to use the > grid manager instead of pack. I can get the plot to show ok but I > can't seem to get the toolbar to show correctly. The following code > does get the toolbar on there but it does use pack for the frame and > also I always end up with an extra blank window (this code is > simplified from something that a Bonnie Douglas posted on this list > recently). > > Any suggestions? > > #!/usr/bin/env python > > import matplotlib > matplotlib.use('TkAgg') > > import Tkinter as Tk > from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, > NavigationToolbar2TkAgg > from matplotlib.figure import Figure > from numpy import arange, sin, pi > > # create toplevel window > tl=Tk.Toplevel() > tl.title("storage") > > # create frame > frame=Tk.Frame(master=tl) > > fig=Figure(figsize=(12,6), dpi=100) > > # create plots > a1 = fig.add_subplot(111) > t = arange(0.0,3.0,0.01) > s = sin(2*pi*t) > a1.plot(t,s) > > # create canvas > canvas=FigureCanvasTkAgg(figure=fig, master=frame) > canvas.show() > > c=canvas.get_tk_widget() > c.grid(row=0, column=0) > > # problems with toolbar not showing solved by setting the master to > # the toplevel window, not the frame!!! > toolbar=NavigationToolbar2TkAgg(canvas, tl) > toolbar.update() > > frame.pack() > > Tk.mainloop() > ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users