-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui2.txt
63 lines (57 loc) · 1.76 KB
/
gui2.txt
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Q1.Create a dict with name and mobile number.Define a GUI interface using tkinter and pack the label and create a scrollbar to scroll the list of keys in the dictionary.
from tkinter import *
root=Tk()
root.title("Users")
root.geometry('250x240')
d={'Simi':7891234123,
'ishu':9801234456,
'navu':8890318789,
'kitu':7799331450,
'noor':7348912123}
f1=Frame(root)
f1.pack()
sb=Scrollbar(f1)
sb.pack(side=RIGHT, fill=Y)
l=Listbox(f1,yscrollcommand=sb.set)
for i in d:
l.insert(END,i)
l.pack(side=LEFT, fill=X)
sb.configure(command=listL.yview)
root.mainloop()
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Q2.In the same tkinter file as created above, create a function to insert items into the dictionary.
from tkinter import *
root=Tk()
root.title("User List!")
root.geometry('250x240')
d={'Simi':7891234123,
'ishu':9801234456,
'navu':8890318789,
'kitu':7799331450,
'noor':7348912123}
f1=Frame(root)
f1.pack()
sb=Scrollbar(f1)
sb.pack(side=RIGHT, fill=Y)
l=Listbox(f1,yscrollcommand=sb.set)
for i in d:
l.insert(END,i)
l.pack(side=LEFT, fill=X)
sb.configure(command=listL.yview)
#adding new entries in dictionary and updating the list
def addval():
d[k.get()]=v.get()
listL.insert(END,k.get())
f=Frame(root)
f.pack()
labelL=Label(f,text="Name ")
labelL.grid(row=0, column=0)
labelL=Label(f,text="Mobile No.")
labelL.grid(row=1,column=0)
k=Entry(f)
k.grid(row=0,column=1)
v=Entry(f)
v.grid(row=1,column=1)
b=Button(f,text="Add in Dictionary",command=addval)
b.grid(row=2,column=1)
root.mainloop()