Joymaker
Joymaker

Reputation: 1428

Tkinter pack add space beteen elements

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?

Upvotes: 1

Views: 1753

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386362

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

Upvotes: 5

Related Questions