Tk - Grid Widget


Advertisements

The grid widget used to layout widgets in specific rows and columns. The syntax for grid widget is shown below −

grid gridName options

Options

The options available for the grid widget are listed below in the following table −

Sr.No. Syntax & Description
1

-column number

Sets the column position for widget.

2

-row number

Sets the row position for widget.

3

-columnspan number

Number of columns to be used for this widget. Defaults to 1.

4

-rowspan number

Number of rows to be used for this widget. Defaults to 1.

5

-sticky side

Sets the edge of the cell to which the widget should stick to. Valid values can be n for top, s for bottom, e for right, w for left, or a combination of these letters.

A simple example for grid widget is shown below −

#!/usr/bin/wish

frame .myFrame1 -background red  -relief ridge -borderwidth 8 -padx 10 -pady 10
   -height 100 -width 100
frame .myFrame2 -background blue  -relief ridge -borderwidth 8 -padx 10 -pady 10
   -height 100 -width 50
grid .myFrame1 -columnspan 10 -rowspan 10 -sticky w
grid .myFrame2 -column 10 -row 2

When we run the above program, we will get the following output −

Grid Example
tk_layout_widgets.htm
Advertisements