Skip to content

Commit 51c0f85

Browse files
committed
Layout managers Python GUI - pack, grid, and place
1 parent a7fb5be commit 51c0f85

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

pack_grid_place/grid.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
__author__ = 'Avinash'
2+
3+
from tkinter import *
4+
5+
Label(text="Label 1", width=10).grid(row=0, column=0)
6+
Label(text="Label 2", width=10).grid(row=0, column=1)
7+
8+
Label(text="Label 3", width=10).grid(row=1, column=0)
9+
Label(text="Label 4", width=10).grid(row=1, column=1)
10+
11+
mainloop()

pack_grid_place/pack.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
__author__ = 'Avinash'
2+
3+
from tkinter import *
4+
5+
root = Tk()
6+
root.geometry('400x400+100+200')
7+
8+
# fill option
9+
label1 = Label(root, text="Label 1", bg="#E74C3C", fg="white").pack(fill=X, padx=10)
10+
label2 = Label(root, text="Label 2", bg="#2ECC71", fg="black").pack(fill=X, padx=10)
11+
label3 = Label(root, text="Label 3", bg="#F1C40F", fg="white").pack(fill=X, padx=10)
12+
13+
# side option
14+
label4 = Label(root, text="Label 1", bg="#34495E", fg="white").pack(fill=X, padx=10, pady=10, side=LEFT)
15+
label5 = Label(root, text="Label 2", bg="#5DADE2", fg="black").pack(fill=X, padx=10, side=LEFT)
16+
label6 = Label(root, text="Label 3", bg="#A569BD", fg="white").pack(fill=X, padx=10, side=LEFT)
17+
18+
# expand option
19+
listbox = Listbox(root)
20+
listbox.pack(fill=BOTH, expand=1)
21+
22+
for i in range(20):
23+
listbox.insert(END, str(i))
24+
25+
mainloop()

pack_grid_place/place.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
__author__ = 'Avinash'
2+
3+
from tkinter import *
4+
root = Tk()
5+
6+
root.geometry('200x200+100+200')
7+
8+
Label(root, text="Label 1 : x=0, y=0", bg="#FFFF00", fg="black").place(x=0, y=0)
9+
Label(root, text="Label 2 : x=50, y=40", bg="#3300CC", fg="white").place(x=50, y=40)
10+
Label(root, text="Label 3 : x=75, y=80", bg="#FF0099", fg="black").place(x=75, y=80)
11+
Label(root, text="Label 4 : x=25, y=100", bg="#00FFFF", fg="white").place(x=25, y=100)
12+
13+
mainloop()

0 commit comments

Comments
 (0)