-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_widget_using_loop.py
More file actions
46 lines (39 loc) · 1.3 KB
/
create_widget_using_loop.py
File metadata and controls
46 lines (39 loc) · 1.3 KB
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
import tkinter as tk
from tkinter import ttk
win=tk.Tk()
win.title('LOOP')
labels = ['What is your name :','What is your age :','What is your gender :','Country :','State :','City :' ]
#name_label=ttk.Label(win,text="What is your name:")
#name_label.grid(row=0,column=0,sticky=tk.W)
for i in range(len(labels)):
cur_label='label'+str(i)
cur_label=ttk.Label(win,text=labels[i])
cur_label.grid(row=i,column=0,sticky=tk.W)
#entrybox
#name_var=tk.StringVar()
#name_entrybox=ttk.Entry(win,width=16,textvariable=name_var)
#name_entrybox.grid(row=0,column=0)
user_info ={
'name':tk.StringVar(),
'age':tk.StringVar(),
'gender':tk.StringVar(),
'country':tk.StringVar(),
'state':tk.StringVar(),
'city':tk.StringVar()
}
counter=0
for i in user_info:
cur_entrybox = 'entry' + i
cur_entrybox=ttk.Entry(win,width=16,textvariable=user_info[i])
cur_entrybox.grid(row=counter,column=1)
counter+=1
def submit():
print(user_info['name'].get())
print(user_info['age'].get())
print(user_info['gender'].get())
print(user_info['country'].get())
print(user_info['state'].get())
print(user_info['city'].get())
submit_button=ttk.Button(win,text="Submit",command=submit)
submit_button.grid(row=6,columnspan=2)
win.mainloop()