Next / Previous / Contents

4. Layout management

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 the .grid() geometry manager for pretty much everything. This manager treats every window or frame as a table—a gridwork of rows and columns.

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:

    self.thing = tk.Constructor(parent, ...)
    self.thing.grid(...)

where Constructor is one of the widget classes like Button, Frame, and so on, and parent is the parent widget in which this child widget is being constructed. All widgets have a .grid() method that you can use to tell the geometry manager where to put it.