Display Matplotlib navigation bar in Tkinter via grid

I am developing a small Tkinter GUI for drawing matplotlib graphs. (It contains several entries and compiles the plot according to their content.)

I designed my build widget according to http://matplotlib.org/examples/user_interfaces/embedding_in_tk.html , only I use the grid instead of the package:

canvas = FigureCanvasTkAgg(fig, master=root) canvas.get_tk_widget().grid(row=1,column=4,columnspan=3,rowspan=20) 

This part works. But embedding the NavigationToolbar in the same way does not occur. Tkinter aborts without errors when I include the lines:

 toolbar = NavigationToolbar2TkAgg( canvas, root ) canvas._tkcanvas.grid(row=22,column=4) 

I know this is because the NavigationToolbar calls pack inside, and pack and grid do not get along with each other. However, I like the grid and I would not want to redo my entire graphical interface to be able to use NavigationToolbar.

Is there a workaround so I can use NavigationToolbar2TkAgg through the grid? (I found advice for “subclassing and overloading” here , but I don’t know how to do this.)

Any help is much appreciated! Lastalda

+7
source share
1 answer

Can you create an empty frame and then put the NavigationToolbar in this frame? I assume that NavigationToolbar will pack itself in this frame. Then you can use the grid in the frame.

+10
source

All Articles