This is an unofficial mirror of Tkinter reference documentation (based on Python 2.7 and Tk 8.5) created by the late John Shipman.
It was last updated in 2013 and is unmaintained. [More info]
Later we will discuss the widgets, the building blocks of your GUI application. How do widgets get arranged in a window?
Although there are three different “geometry
managers” in Tkinter, the author strongly prefers
.grid() geometry manager for pretty much
everything. This manager treats every window or frame as a
table—a gridwork of rows and columns.
A cell is the area at the intersection of one row and one column.
The width of each column is the width of the widest cell in that column.
The height of each row is the height of the largest cell in that row.
For widgets that do not fill the entire cell, you can specify what happens to the extra space. You can either leave the extra space outside the widget, or stretch the widget to fit it, in either the horizontal or vertical dimension.
You can combine multiple cells into one larger area, a process called spanning.
When you create a widget, it does not appear until you register it with a geometry manager. Hence, construction and placing of a widget is a two-step process that goes something like this:
parent, ...) self.
is one of the widget classes like
Frame, and so on, and
the parent widget in which this child widget is being
constructed. All widgets have a
method that you can use to tell the geometry manager where
to put it.