How to add space between two widgets placed in a grid in tkinter?


Let us assume that we are creating a tkinter application where two or more widgets are placed using a grid property. We have to add some space between the widgets in order to style their appearance. To provide space in the widgets, we can use padding property, as padding adds space to the outermost part of the widget. In order to add padding, assign the values to padx and pady.

Example

#Import the required library
from tkinter import *
#create an instance of tkinter frame
win= Tk()
win.geometry("750x250")
#Create some Button widgets
Label(win, text= "New Line Text", font= ('Helvetica 20 bold')).grid(row=0, column=5, padx= 25, pady= 25)
Button(win, text= "Button 1").grid(row=0, column=1, padx= 50, pady= 80)
Button(win, text= "Button 2").grid(row=0, column=2, padx= 25, pady =36)
win.mainloop()

Output

Updated on: 15-Apr-2021

7K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements