Next / Previous / Contents

4.2. Other grid management methods

These grid-related methods are defined on all widgets:

w.grid_bbox(column=None, row=None, col2=None, row2=None)

Returns a 4-tuple describing the bounding box of some or all of the grid system in widget w. The first two numbers returned are the x and y coordinates of the upper left corner of the area, and the second two numbers are the width and height.

If you pass in column and row arguments, the returned bounding box describes the area of the cell at that column and row. If you also pass in col2 and row2 arguments, the returned bounding box describes the area of the grid from columns column to col2 inclusive, and from rows row to row2 inclusive.

For example, w.grid_bbox(0, 0, 1, 1) returns the bounding box of four cells, not one.

w.grid_forget()

This method makes widget w disappear from the screen. It still exists, it just isn't visible. You can use .grid() it to make it appear again, but it won't remember its grid options.

w.grid_info()

Returns a dictionary whose keys are w's option names, with the corresponding values of those options.

w.grid_location(x, y)

Given a coordinates (x, y) relative to the containing widget, this method returns a tuple (col, row) describing what cell of w's grid system contains that screen coordinate.

w.grid_propagate()

Normally, all widgets propagate their dimensions, meaning that they adjust to fit the contents. However, sometimes you want to force a widget to be a certain size, regardless of the size of its contents. To do this, call w.grid_propagate(0) where w is the widget whose size you want to force.

w.grid_remove()

This method is like .grid_forget(), but its grid options are remembered, so if you .grid() it again, it will use the same grid configuration options.

w.grid_size()

Returns a 2-tuple containing the number of columns and the number of rows, respectively, in w's grid system.

w.grid_slaves(row=None, column=None)

Returns a list of the widgets managed by widget w. If no arguments are provided, you will get a list of all the managed widgets. Use the row= argument to select only the widgets in one row, or the column= argument to select only the widgets in one column.