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

TkinterServer Side ProgrammingProgramming

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.


#Import the required library
from tkinter import *
#create an instance of tkinter frame
win= Tk()
#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)


Updated on 15-Apr-2021 13:59:13