How to make matplotlib: pyplot resizeable with a Tkinter window in Python?

I am trying to build a grid of frames in each matplotlib shape. When I resize the window, the shape remains with the patch size and does not resize to fit the empty space. Is there a way to make the figure resize to fit the canvas (hope it resizes with the window)?

before expanding the windowafter expanding the window

This is how I embed in every frame:

self._figure = pyplot.figure(figsize=(4,4)) self._axes = self._figure.add_subplot(111) self._canvas = FigureCanvasTkAgg(self._figure, master=self._root) self._canvas.get_tk_widget().grid(row=1,column=1,rowspan = 4) 
+4
source share
1 answer

This is most likely related to this issue . The bottom line is that there are two parts to creating a Tk grid cell:

  • Use the sticky keyword when applying grid to your widget, for example widget.grid(..., sticky=Tkinter.NSEW (Python 2.7) so that the widget can grow in all four directions. See this documentation for more details.
  • Tell the parent / master that the corresponding column / row grows when resized by calling parent.grid_columnconfigure(...) and / or parent.grid_rowconfigure(...) with the desired keyword, column and weight . For example, parent.grid_columnconfigure(col=0, weight=1) makes the first column occupy all available space (if there are no other columns or they were not configured in this way). See the grid_columnconfigure configuration file and the grid_rowconfigure configuration file for more information. Details, such as how weight affects multiple columns / rows.

This page contains more information about grid layouts.

0
source

Source: https://habr.com/ru/post/1501083/


All Articles