-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment18.py
More file actions
67 lines (52 loc) · 1.62 KB
/
Assignment18.py
File metadata and controls
67 lines (52 loc) · 1.62 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#(Q.1)- 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 *
window = Tk()
window.title('App1')
window.maxsize(300,65)
listbox = Listbox(window)
listbox.pack(side=LEFT,fill=Y)
d={'Vibhor':96710,'Vinay':63513,'Rahul':89302,'Yash':88973,'Mahi':98131}
for k in d.keys():
listbox.insert(END,k)
scroll = Scrollbar(window,command=listbox.yview)
scroll.pack(side=RIGHT,fill=Y)
listbox.config(yscrollcommand=scroll.set)
label = Label(window,text="Window",bg="pink")
label.pack()
#(Q.2)- In the same tkinter file as created above, create a function to insert items into the dictionary.
def show():
k = listbox.get(ACTIVE)
v = d[k]
label1.config(text=k)
label2.config(text=v)
def insert():
k = box1.get()
v = box2.get()
d[k] = v
listbox.insert(END,k)
print(d)
window = Tk()
window.title('App2')
window.maxsize(350,150)
listbox = Listbox(window)
listbox.pack(side=LEFT,fill=Y)
d={'Vibhor':96710,'Vinay':63513,'Rahul':89302,'Yash':88973,'Mahi':98131}
for k in d.keys():
listbox.insert(END,k)
scroll = Scrollbar(window,command=listbox.yview)
scroll.pack(side=RIGHT,fill=Y)
listbox.config(yscrollcommand=scroll.set)
label1 = Label(window,text="Name",bg="pink",font=10)
label1.pack()
label2 = Label(window,text="Number",bg="green",font=10)
label2.pack()
button1 = Button(window,text="Show",command=show)
button1.pack()
box1 = Entry(window)
box1.pack()
box2 = Entry(window)
box2.pack()
button2 = Button(window,text="Insert",command=insert)
button2.pack()
window.mainloop()