Page Nav

HIDE

Left Sidebar

TO-LEFT

Breaking News

latest

How to add frames(margin) in tkinter - Full Explained?

How to add frames(margin) in tkinter? Code to add frames(margin) ''' # code from tkinter import * root = Tk() root.geometry(...

How to add frames(margin) in tkinter?

Code to add frames(margin)

'''

# code

from tkinter import *

root = Tk()

root.geometry("333x573")

frame1 = Frame(root, bg="red", borderwidth=4, relief=SUNKEN)

frame1.pack(side=LEFT, fill="y")

root.mainloop()

f2 = Frame(root, borderwidth=8, bg="grey", relief=SUNKEN)

f2.pack(side=TOP, fill="x")

l1 = Label(f1, text="Project Tkinter - vscode")

l1.pack(pady=105)

root.mainloop()

''''

You can add margin with this code and You have to understand this code first . So how that you can customize the program.

from tkinter import *

This code is written for importing a module in python and module name is tkinter and import * is import every thing from tkinter.

root=tk()

root=tk() is a main tkinter variable after this we start to write our code it is the main variable in which we use it almost every where.

root.geometry("333x573")

root.geometry("333x573") is used to specify the size of our window means x*y in here we write like this ("XxY") we use "x" as multiply.

frame1 = Frame(root, bg="red", borderwidth=4, relief=SUNKEN)

frame1 = Frame() is used to make frame (root) is used to specify that we have to paste it on root bg=red is used to set background color borderwidth=4 is used to specify border width relief=SUNKEN is used to specify the type of border.

frame1.pack(side=LEFT, fill="y")

frame1.pack(side=LEFT, fill="y") it is used to specify to pack the frame side=left is used to where we have to pack it fill = "y" is used to specify that take all the space in y axis.

l1 = Label(f1, text="Project Tkinter - vscode")

l1 = Label(f1, text="Project Tkinter - Pycharm") is a label in which we are trying to print text simply here you can write any thing.

l1.pack(pady=105)

l1.pack(pady=142) is used to give the padding if you don't know about padding in simple sentences padding is a space given by programmer to keep the window clean.

root.mainloop()

root.mainloop() is used to specify the end of our tkinter code.

I hope you understand every thing that I tell you

By Nikunj gupta

By technical-gyan-double.blogspot.com

No comments