code: def zoom_fit(self):
          
  
          zoom = self.grid.grid_renderer.zoom
  
          grid_width, grid_height = self.grid.GetSize()
  
          rows_height = self._get_rows_height() + \
              (float(self.grid.GetColLabelSize()) / zoom)
          cols_width = self._get_cols_width() + \
              (float(self.grid.GetRowLabelSize()) / zoom)
  
          # Check target zoom for rows
          zoom_height = float(grid_height) / rows_height
  
          # Check target zoom for columns
          zoom_width = float(grid_width) / cols_width
  
          # Use the minimum target zoom from rows and column target zooms
          target_zoom = min(zoom_height, zoom_width)
  
          # Zoom only if between min and max
  
          if config["minimum_zoom"] < target_zoom < config["maximum_zoom"]:
              self.zoom(target_zoom)
docs: Zooms the rid to fit the window.
  
          Only has an effect if the resulting zoom level is between
          minimum and maximum zoom level.