-
Notifications
You must be signed in to change notification settings - Fork 531
/
Copy path6-control-layout-with-geometry-managers.py
48 lines (40 loc) · 1.46 KB
/
6-control-layout-with-geometry-managers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import tkinter as tk
# Creating a window with a title
window = tk.Tk()
window.title("Address Entry Form")
# List of fields we want to have in our form
fields = ["First Name:",
"Last Name:",
"Address Line1:",
"Address Line2:",
"City:",
"State/Province:",
"Postal Code:",
"Country:"]
# The top frame contains the fields and their entry widgets
top_frame = tk.Frame(relief=tk.SUNKEN, master = window)
top_frame.pack()
# We are going to use a 2 columns grid to place our widgets
# We initialise the current row variable of our grid
current_top_frame_row = 0
for field in fields:
# For each field we create a label and entry widget
label = tk.Label(text=field, master=top_frame)
entry = tk.Entry(width=50, master=top_frame)
# We place them in the current row of our grid
label.grid(row=current_top_frame_row, column=0, sticky=tk.E)
entry.grid(row=current_top_frame_row, column=1)
# We increment the current line for the next field
current_top_frame_row += 1
# Creating the bottom frame that contains
# the Submit & Clear buttons
bot_frame = tk.Frame(master=window)
bot_frame.pack(fill=tk.X, ipadx=5, ipady=5)
choices = ["Cancel",
"Submit"]
for choice in choices:
# Create the button and pack it to the right side
button = tk.Button(text=choice, relief=tk.RAISED, master=bot_frame)
button.pack(side=tk.RIGHT, padx=5, ipadx=10)
# Start the application
window.mainloop()