The padding options padx and pady of the grid and pack methods can take a 2-tuple that represent the left/right and top/bottom padding.
Here's an example:
import tkinter as tk
class MyApp():
def __init__(self):
self.root = tk.Tk()
l1 = tk.Label(self.root, text="Hello")
l2 = tk.Label(self.root, text="World")
l1.grid(row=0, column=0, padx=(100, 10))
l2.grid(row=1, column=0, padx=(10, 100))
app = MyApp()
app.root.mainloop()
Answer from Bryan Oakley on Stack OverflowThe padding options padx and pady of the grid and pack methods can take a 2-tuple that represent the left/right and top/bottom padding.
Here's an example:
import tkinter as tk
class MyApp():
def __init__(self):
self.root = tk.Tk()
l1 = tk.Label(self.root, text="Hello")
l2 = tk.Label(self.root, text="World")
l1.grid(row=0, column=0, padx=(100, 10))
l2.grid(row=1, column=0, padx=(10, 100))
app = MyApp()
app.root.mainloop()
There are multiple ways of doing that you can use either place or grid or even the packmethod.
Sample code:
from tkinter import *
root = Tk()
l = Label(root, text="hello" )
l.pack(padx=6, pady=4) # where padx and pady represent the x and y axis respectively
# well you can also use side=LEFT inside the pack method of the label widget.
To place a widget to on basis of columns and rows , use the grid method:
but = Button(root, text="hello" )
but.grid(row=0, column=1)
ipadx/ipady Only Pad right/bottom on tkinter Frame with Grid Layout Manager
TKinter / make some space between elements?
Videos
Hello - i have created the following application - but i would like to make more space between the elements -(i tried it with padx and pady - but with this commands i only get the elements "bigger" but not more space BETWEEN the elements)
https://ibb.co/94sMgmv
eg. for the Buttons(only spacing with this inside the button - but not around them)
myB = Button(root,text="Generate",command=show,padx=10,pady=10) myB2 = Button(root,text="Reset",command=reset,padx=10,pady=10)
I would need something like "margin" in css for tkinter?Is there anything similar?