Using padding to add space around widgets
Our GUI is being created nicely. Next, we will improve the visual aspects of our widgets by adding a little space around them, so they can breathe...
Getting ready
While tkinter might have had a reputation for creating ugly GUIs, this has dramatically changed since version 8.5, which ships with Python 3.4.x. You just have to know how to use the tools and techniques that are available. That's what we will do next.
How to do it...
The procedural way of adding spacing around widgets is shown first, and then we will use a loop to achieve the same thing in a much better way.
Our LabelFrame looks a bit tight as it blends into the main window towards the bottom. Let's fix this now.
Modify the following line of code by adding padx
and pady
:
labelsFrame.grid(column=0, row=7, padx=20, pady=40)
And now our LabelFrame got some breathing space:
How it works...
In tkinter, adding space horizontally and vertically is done by using the built-in properties named padx
and pady...