How to add a margin to a tkinter window?

The margin of a tkinter window can be controlled by specifying the value of fill, expand and padding. Another way to set the margin of a tkinter window is to use grid(**options) Geometry Manager. Grid pack manager allows us to add the margin by specifying the value of row and column property.


# Import the required library
from tkinter import *
from tkinter import ttk

# Create an instance of tkinter frame
win= Tk()

# Set the size of the Tkinter window

# Add a frame to set the size of the window
frame= Frame(win, relief= 'sunken', bg= "black")
frame.pack(fill= BOTH, expand= True, padx= 10, pady=20)

# Add a label widget
label= Label(frame, text= "Welcome to Tutorialspoint",
font=('Helvetica 15 bold'), bg= "white")
label.pack(pady= 30)



Executing the above code will display a Label Text lying inside a frame. The margin of the frame is expandable and resizable.

Updated on: 07-Jun-2021

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started