-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson65 - Tkinter Address book.py
More file actions
71 lines (53 loc) · 1.81 KB
/
lesson65 - Tkinter Address book.py
File metadata and controls
71 lines (53 loc) · 1.81 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
68
69
70
71
# Creating address book using Tkinter
from tkinter import *
root = Tk()
root.geometry('400x500')
datas = []
def add():
global datas
datas.append([Name.get(),Number.get(),address.get(1.0, "end-1c")])
update_book()
def view():
Name.set(datas[int(select.curselection()[0])][0])
Number.set(datas[int(select.curselection()[0])][1])
address.delete(1.0,"end")
address.insert(1.0, datas[int(select.curselection()[0])][2])
def delete():
del datas[int(select.curselection()[0])]
update_book()
def reset():
Name.set('')
Number.set('')
address.delete(1.0, "end")
def update_book():
select.delete(0, END)
for n,p,a in datas:
select.insert(END, n)
Name = StringVar()
Number = StringVar()
# Frames
frame = Frame()
frame.pack(pady=10)
frame1 = Frame()
frame1.pack()
frame2 = Frame()
frame2.pack(pady=10)
# Adding elements into frames
Label(frame, text='Name', font="arial 12 bold").pack(side=LEFT)
Entry(frame, textvariable = Name, width=50).pack()
Label(frame1, text='Phone No', font="arial 12 bold").pack(side=LEFT)
Entry(frame1, textvariable = Number, width=50).pack()
Label(frame2, text='Address', font="arial 12 bold").pack(side=LEFT)
address = Text(frame2, width=37, height=10)
address.pack()
# Adding buttons for functions
Button(root, text="Add", font="arial 12 bold",command=add).place(x=100, y=270)
Button(root, text="View", font="arial 12 bold",command=view).place(x=100, y=310)
Button(root, text="Delete", font="arial 12 bold",command=delete).place(x=100, y=350)
Button(root, text="Reset", font="arial 12 bold",command=reset).place(x=100, y=390)
scroll_bar = Scrollbar(root, orient=VERTICAL)
select = Listbox(root, yscrollcommand=scroll_bar.set, height=12)
scroll_bar.config(command=select.yview)
scroll_bar.pack(side=RIGHT, fill=Y)
select.place(x=200, y=260)
root.mainloop()