Displaying Matplotlib Navigation Toolbar in Tkinter via grid

Can you create an empty frame, then put the NavigationToolbar in that frame? I assume the NavigationToolbar will then pack itself in that frame. You can then use grid on the frame.


# the following works for me. I created an empty frame and display it using the grid
# management system, so the frame will be able to use pack management system
canvas = FigureCanvasTkAgg(fig, root)
canvas.draw()
canvas.get_tk_widget().grid(row=2, column=0)
frame = Frame(root)
frame.grid(row=0, column=1)
toobar = NavigationToolbar2Tk(canvas, frame)
canvas.get_tk_widget().grid(row=1, column=0)

Here is a code example for what was mentioned in Bryan Oakleys answer (add toolbar to frame, place frame on grid):

    fig = Figure(figsize=(5, 5), dpi=100)

    canvas = FigureCanvasTkAgg(fig, master=root)
    canvas.get_tk_widget().grid(row=1,column=4,columnspan=3,rowspan=20)
    # here: plot suff to your fig
    canvas.draw()

    ###############    TOOLBAR    ###############
    toolbarFrame = Frame(master=root)
    toolbarFrame.grid(row=22,column=4)
    toolbar = NavigationToolbar2TkAgg(canvas, toolbarFrame)

I believe what you're looking for is the pack_toolbar=False kwarg
Your toolbar definition should look something like this:

toolbar = NavigationToolbar2Tk(canvas, root, pack_toolbar=False)

The following two lines are executed within the NavigationToolbar2TK constructor:

if pack_toolbar:
        self.pack(side=tk.BOTTOM, fill=tk.X)

So setting pack_toolbar to False disables the internal packing, allowing you to use to use grid as per usual.

toolbar.grid()