In this tutorial we are going to focus on the third of the layout managers in Tkinter, place, to get you on your way to building GUI applications.

If you are curious about the other layout managers, or not sure which one to use for your projects, you can check out my other tutorials:

The Place Layout Manager

The place layout manager allows for you to have more absolute control about the arrangement of your widgets. With place, you can specify the size of the widget, as well as the exact x and y coordinates to arrange it within the parent window. In many cases, this can prove to be easier when you are thinking about the layout of your GUI. But it also means that you may have to spend a little more time playing around with the x and y values.

The place manager is most useful for arranging buttons or other smaller widgets together within a larger dialog window.

A few of the parameters you can play around with are listed below.

  • in_ – specify the master window for the widget.
  • x, y – specify the specific and y values of the widget in the parent window.
  • relx, rely – horizontal and vertical offset relative to the size of the parent widget, values between 0.0 and 0.1.
  • relwidth, relheight – set height and width of widget relative to the size of the parent widget, values between 0.0 and 0.1.
  • anchor – where the widget is placed in the parent widget, specified by n, s, e, w, or some combination of them. Default is center.

Create a Simple GUI with Place

Let’s take a look at a simple example to learn how to lay out widgets using place. Below we create a program that asks the user a question and allows the user to select an option from a list, using a Listbox, before closing the window.

The code above will produce the following GUI:

Tkinter GUI window created using place layout manager
Example GUI application using place.

The GUI application itself is very simple consisting of a label, a listbox and a button. The example above only shows how to use absolute positioning by setting the x and y values. In lines 10, 14 and 28, each widget is arranged in the window by specifying these values.

Summary

Today’s post covers some of the fundamentals of using place for layout management in Tkinter to create a GUI application. While this method may be a bit more time-consuming to use, it is very useful when you want more control over the exact location of your widgets.

In following posts, we’ll be getting into using some of Tkinter’s other widgets. As always, if you have any questions of comments I would really enjoy hearing them!

Twitter
Visit Us
Facebook
LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *