Pack() Method
Tkinter also offers access to the geometric configuration of the widgets which can organize the widgets in the parent windows. There are mainly three geometry manager classes class.
Thete 3 Methids In Python Tkinter
Pack() method:-
It organizes the widgets in blocks before placing in the parent widget.
Grid() method:-
It organizes the widgets in grid (table-like structure) before placing in the parent widget.
Place() method:-
It organizes the widgets by placing them on specific positions directed by the programmer.
Pack() Method:-
- Pack is the easiest to use of the three geometry managers of Tk and Tkinter.
- Instead of having to declare precisely where a widget should appear on the display screen, we can declare the positions of widgets with the pack command relative to each other.
- The pack command takes care of the details.
- Though the pack command is easier to use, this layout managers is limited in its possibilities compared to the grid and place mangers.
- For simple applications it is definitely the manager of choice.
- For example simple applications like placing a number of widgets side by side, or on top of each other.
Example:-
from Tkinter import *
root = Tk()
Label(root, text="Red Sun", bg="red", fg="white").pack()
Label(root, text="Green Grass", bg="green", fg="black").pack()
Label(root, text="Blue Sky", bg="blue", fg="white").pack()
mainloop()
OutPut:-
Fill: If you want to make the widgets as wide as the parent widget, you have to use the fill=X option:
from Tkinter import *
root = Tk()
w = Label(root, text="Red Sun", bg="red", fg="white")
w.pack(fill=X)
w = Label(root, text="Green Grass", bg="green", fg="black")
w.pack(fill=X)
w = Label(root, text="Blue Sky", bg="blue", fg="white")
w.pack(fill=X)
mainloop()
Padding:-
The pack() manager knows four padding options, i.e. internal and external padding and padding in x and y direction:
padx External padding, horizontally
pady External padding, vertically
ipadx Internal padding, horizontally.
ipady Internal padding, vertically
How Horizontally Working in Tkinter:-
padx External padding, horizontally
from Tkinter import *
root = Tk()
w = Label(root, text="Red Sun", bg="red", fg="white")
w.pack(fill=X,padx=10)
w = Label(root, text="Green Grass", bg="green", fg="black")
w.pack(fill=X,padx=10)
w = Label(root, text="Blue Sky", bg="blue", fg="white")
w.pack(fill=X,padx=10)
mainloop()
How Vertically Working in Tkinter:-
pady External padding, vertically
from Tkinter import *
root = Tk()
w = Label(root, text="Red Sun", bg="red", fg="white")
w.pack(fill=X,pady=10)
w = Label(root, text="Green Grass", bg="green", fg="black")
w.pack(fill=X,pady=10)
w = Label(root, text="Blue Sky", bg="blue", fg="white")
w.pack(fill=X,pady=10)
mainloop()
How Horizontally Working in Tkinter:-
ipadx Internal padding, horizontally.
from Tkinter import *
from Tkinter import *
root = Tk()
w = Label(root, text="Red Sun", bg="red", fg="white")
w.pack()
w = Label(root, text="Green Grass", bg="green", fg="black")
w.pack(ipadx=10)
w = Label(root, text="Blue Sky", bg="blue", fg="white")
w.pack()
mainloop()
How Vertically Working in Tkinter:-
from Tkinter import *
root = Tk()
w = Label(root, text="Red Sun", bg="red", fg="white")
w.pack()
w = Label(root, text="Green Grass", bg="green", fg="black")
w.pack(ipadx=10)
w = Label(root, text="Blue Sky", bg="blue", fg="white")
w.pack(ipady=10)
mainloop()
The default value in all cases is 0.
Placing widgets side by side
from Tkinter import *
root = Tk()
w = Label(root, text="red", bg="red", fg="white")
w.pack(padx=5, pady=10, side=LEFT)
w = Label(root, text="green", bg="green", fg="black")
w.pack(padx=5, pady=20, side=LEFT)
w = Label(root, text="blue", bg="blue", fg="white")
w.pack(padx=5, pady=20, side=LEFT)
mainloop()
To Next Artical We Discuss About How to Use grid And Place Method In Python...
Basic introduction To Tkinter and how to install Click The Link
Check Out Our Python ALL Post In Just One Click....
8 Comments
Samsun
ReplyDeleteNevÅŸehir
Van
Bartın
Edirne
AYYE41
https://bayanlarsitesi.com/
ReplyDeleteAltınşehir
Karaköy
AlemdaÄŸ
Gürpınar
BSPD5D
Denizli
ReplyDeleteKonya
Denizli
ısparta
Bayburt
T3BPBÄ°
Afyon
ReplyDeleteAntalya
Erzurum
Mersin
izmir
VKC
kırklareli evden eve nakliyat
ReplyDeleteısparta evden eve nakliyat
istanbul evden eve nakliyat
ankara evden eve nakliyat
kırıkkale evden eve nakliyat
RTQF
D0C77
ReplyDeleteBilecik Lojistik
Siirt Şehirler Arası Nakliyat
Batman Şehir İçi Nakliyat
Isparta Parça Eşya Taşıma
Iğdır Lojistik
Mardin Lojistik
Kütahya Lojistik
Bitci Güvenilir mi
Sakarya Evden Eve Nakliyat
E9104
ReplyDeletebinance indirim kodu %20
A1A27
ReplyDeletekarabük görüntülü sohbet uygulamaları ücretsiz
malatya rastgele sohbet
tokat bedava sohbet siteleri
en iyi rastgele görüntülü sohbet
yalova sesli sohbet sesli chat
rastgele sohbet odaları
maraş görüntülü sohbet canlı
zonguldak kızlarla rastgele sohbet
sivas sesli sohbet siteler