I have some code that opens a plot in a tkinter toplevel widget. When I grab the corner of the toplevel to resize it, I would like the plot to resize along with the window.
import Tkinter
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.backends.backend_tkagg import NavigationToolbar2TkAgg
from matplotlib.figure import Figure
class grapher_gui(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.parent = parent
self.graph()
def graph(self):
x_vals = [0,3,10,15]
y_vals = [232,120,45,23]
toplevel = Tkinter.Toplevel(width=2000)
figure = Figure(figsize=(10,5))
ax = figure.add_subplot(111)
plot = ax.plot(x_vals, y_vals, 'k-')
ax.set_xlabel('Time')
ax.set_ylabel('Numbers')
ax.set_title('Title')
canvas = FigureCanvasTkAgg(figure, master=toplevel)
canvas.show()
canvas.get_tk_widget().grid(row=0)
toolbar = NavigationToolbar2TkAgg(canvas, toplevel)
toolbar.grid(row=1, sticky=Tkinter.W)
toolbar.update()
toplevel.mainloop()
if __name__ == "__main__":
app = grapher_gui(None)
app.title('Grapher')
app.mainloop()
The only thing I could think of to try was adding sticky='NSEW'
to canvas.get_tk_widget().grid(row=0)
, but that doesn't work.