VOOZH about

URL: https://www.geeksforgeeks.org/python/python-grid-method-in-tkinter/

⇱ Python | grid() method in Tkinter - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python | grid() method in Tkinter

Last Updated : 24 Mar, 2026

The grid() method in Tkinter is used to arrange widgets in a window using a row-and-column layout. It places widgets inside a container (such as a window or frame) in a two-dimensional table structure. Each widget is assigned a specific row and column position. The grid size is determined automatically based on the widgets added.

Example: This example creates a window with one label placed using the grid() method.

Output

πŸ‘ Screenshot-2026-03-05-153856
output

Explanation: l.grid(row=0, column=0) places the label in the first row and first column of the window.

Syntax

widget.grid(options)

Common Parameters:

  • row: Row number where the widget is placed.
  • column: Column number where the widget is placed.
  • rowspan: Number of rows the widget spans.
  • columnspan: Number of columns the widget spans.
  • padx / pady: Extra space around the widget (horizontal/vertical).
  • sticky: Aligns the widget inside the cell (N, S, E, W).

Examples

Example 1: This program creates a basic form with labels and entry fields. Each widget is positioned using specific row and column values.

Output

πŸ‘ Screenshot-2026-03-05-154255
A window displaying two labels (β€œName”, β€œAge”) with corresponding input fields arranged in two rows.

Explanation: Each widget is placed using grid(row=?, column=?), which positions it inside the table layout.

Example 2: This example creates a button that spans across two columns. It shows how to merge grid cells horizontally.

Output

πŸ‘ Screenshot-2026-03-05-154507
A window where the β€œLogin” button stretches across both columns below the entry field.

Explanation: columnspan=2 makes the button extend across two columns.

Example 3: This program demonstrates how to align widgets inside their grid cells. It uses the sticky option for alignment control.

Output

πŸ‘ Screenshot-2026-03-05-160522
A window where one label aligns to the left of its cell and the other aligns to the right.

Explanation: sticky=W aligns the widget to the left and sticky=E aligns it to the right inside the grid cell.

Comment
Article Tags: