-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphonebook.py
95 lines (66 loc) · 2.11 KB
/
phonebook.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import tkinter as tk
from tkinter import *
root = Tk()
root.geometry('400x400')
root.config(bg='SlateGray3')
root.resizable(0, 0)
root.title("Address book")
contact_list = [
['Shubham', '8944653345'],
['shakuni', '666666666'],
['fomo', '5698356784'],
]
Name = StringVar()
Number = StringVar()
frame = Frame(root)
frame.pack(side=RIGHT)
scroll = Scrollbar(frame, orient=VERTICAL)
select = Listbox(frame, yscrollcommand=scroll.set, height=12)
scroll.config(command=select.yview)
scroll.pack(side=RIGHT, fill=Y)
select.pack(side=LEFT, fill=BOTH, expand=1)
def Selected():
return int(select.curselection()[0])
def AddContact():
contact_list.append([Name.get(), Number.get()])
Select_set()
def EDIT():
contact_list[Selected()] = [Name.get(), Number.get()]
Select_set()
def DELETE():
del contact_list[Selected()]
Select_set()
def VIEW():
NAME, PHONE = contact_list[Selected()]
Name.set(NAME)
Number.set(PHONE)
def EXIT():
root.destroy()
def RESET():
Name.set('')
Number.set('')
def Select_set():
contact_list.sort()
select.delete(0, END)
for name, phone in contact_list:
select.insert(END, name)
Select_set()
Label(root, text='NAME', font='arial 12 bold ',
bg='SlateGray3').place(x=30, y=20)
Entry(root, textvariable=Name).place(x=100, y=20)
Label(root, text='PHONE NO.', font='arial 12 bold ',
bg='SlateGray3').place(x=30, y=70)
Entry(root, textvariable=Number).place(x=130, y=70)
Button(root, text='ADD', font='arial 12 bold ',
bg='SlateGray4', command=AddContact).place(x=50, y=110)
Button(root, text='EDIT', font='arial 12 bold ',
bg='SlateGray4', command=EDIT).place(x=50, y=260)
Button(root, text='DELETE', font='arial 12 bold ',
bg='SlateGray4', command=DELETE).place(x=50, y=210)
Button(root, text='VIEW', font='arial 12 bold ',
bg='SlateGray4', command=VIEW).place(x=50, y=160)
Button(root, text='EXIT', font='arial 12 bold ',
bg='SlateGray4', command=EXIT).place(x=300, y=320)
Button(root, text='RESET', font='arial 12 bold ',
bg='SlateGray4', command=RESET).place(x=50, y=310)
root.mainloop()