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.

Example

# 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 win.geometry("700x350") # 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) win.mainloop()

Output

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

Updated on: 2021-06-07T11:08:16+05:30

8K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements