Layout Manager in tkinter Python(pading)
When you create graphical interfaces, the widgets in the window must have a way to be arranged relative to each other. Tkinter there are three types of layout managers -- pack, place, and grid. Each manager uses a different method to help us arrange widgets.
Pack Layout Manager :
Pack() method turns each individual widget into a block. Each widget has its own size and the pack manager fits them all together just like you would do with real blocks. The manager stacks widgets on top of each other vertically like blocks. Of course, you can also achieve a horizontal layout by changing the side parameter to 'left' or 'right'. You can also change the height, width, and locations of the widgets.
Attributes of Pack Geometry manager:
(i)side -- specifies the general location of the widget in the window, arguments are 'top', 'bottom', 'left', 'right' (default is 'top').
(ii)fill -- which directions you want the widget to fill in the parent window, can choose 'x', 'y' directions, or 'both'.
(iii) padx, pady -- the number of pixels surrounding the widget to create a padding between other widgets, for horizontal or vertical padding.
(iv)ipadx, ipady -- how many pixels to use for padding inside the widget, also for horizontal or vertical padding
(v)expand -- set to True if you want the widget to stretch if the parent window expands. Default is False.
(vi)anchor -- where the widget is placed in the parent widget, specified by 'n', 's', 'e', 'w', or some combination of them. Default is 'center'.
In this example we will understand about “padding“ attribute in pack geometry manager.
from tkinter import *
root = Tk()
root.title("This is Padx Pady Example")
root.geometry("800x400+450+86")
root.config(bg="#FFEFDB")lbl1=Label(root,text="JOHNY", bg="#FF6103", fg="white")
lbl1.pack(pady=20)lbl2=Label(root,text="HASAN", bg="#66CD00", fg="white")
lbl2.pack(fill=X)lbl3=Label(root,text="JOHNY HASAN", bg="#0000EE", fg="white")
lbl3.pack(pady=20)root.mainloop()
Write Down Code Your Code Editor. To show Your Output. If Use Pycharm Press Shift+F10 and Show Your Output.
If You Want to Know More About Layout Manager Plz visit Below Link
Post a Comment