I'm developing a small Tkinter GUI to draw matplotlib-plots. (It contains a few Entries and assembles the plot according to their content.)
I have designed my plotting widget according to http://matplotlib.org/examples/user_interfaces/embedding_in_tk.html, only I use grid instead of pack:
canvas = FigureCanvasTkAgg(fig, master=root) canvas.get_tk_widget().grid(row=1,column=4,columnspan=3,rowspan=20)
That part works. But embedding the NavigationToolbar in the same fashion does not. Tkinter breaks down without error when I include the lines:
toolbar = NavigationToolbar2TkAgg( canvas, root ) canvas._tkcanvas.grid(row=22,column=4)
I know this is because NavigationToolbar calls pack
internally, and pack
and grid
don't get along. However, I like grid and would hate to have to redesign my whole GUI just to be able to use the NavigationToolbar.
Is there a workaround so I can use NavigationToolbar2TkAgg via grid? (I have found the advice to "subclass and overload" here, but don't know how to do that.)
Any help greatly appreciated!
To create a grid, you need to use the .The grid() method allows you to indicate the row and column positioning in its parameter list. Both row and column start from index 0. For example grid(row=1, column=2) specifies a position on the third column and second row of your frame or window.
Matplotlib charts by default have a toolbar at the bottom. When working with Tkinter, however, this toolbar needs to be embedded in the canvas separately using the NavigationToolbar2Tk() class.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With