Home > Software engineering >  Tkinter pack add space beteen elements
Tkinter pack add space beteen elements

Time:09-16

If I'm using the tkinter pack manager and I just want to add some space horizontally between two items, what is the best way to do it? I understand padx, pady, ipadx, and ipady, but they add space AROUND an item on both sides. Unfortunately I don't see padleft, padright, anything of that nature to just add space BETWEEN two items. What is the best practice here? Just create a little frame and stick it between the visible items?

CodePudding user response:

padx and pady can be a single value, or a tuple of two values. When given two values, padx uses the first value for the left and the second value for the right. Similarly, pady uses the first value for the top and the second value for the bottom.

import tkinter as tk
root = tk.Tk()
label = tk.Label(root, text="Padding example")

label.pack(padx=(0, 100), pady=(100, 0))

root.mainloop()

screenshot

  • Related