-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesktop_controller.py
More file actions
94 lines (72 loc) · 2.44 KB
/
desktop_controller.py
File metadata and controls
94 lines (72 loc) · 2.44 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# coding=utf-8
from Tkinter import *
import tkMessageBox
from configurer import contacts
root = Tk()
tl = None
l_name = Label(root, text="Name")
l_name.grid(row=0, column=0)
e_name = Entry(root)
e_name.grid(row=0, column=1)
l_phone = Label(root, text="Phone")
l_phone.grid(row=1, column=0)
e_phone = Entry(root)
e_phone.grid(row=1, column=1)
def clear_entries():
e_name.delete(0, END)
e_phone.delete(0, END)
def ask_create_contact():
try:
contacts.create_contact(e_name.get(), e_phone.get())
clear_entries()
tkMessageBox.showinfo("Success", "Contact added")
except ValueError as e:
tkMessageBox.showerror("Error", e)
def ask_find_contact():
try:
phone = contacts.find_contact(e_name.get())
e_phone.delete(0, END)
e_phone.insert(0, phone)
except ValueError as e:
tkMessageBox.showerror("Error", e)
def ask_update_contact():
try:
contacts.update_contact(e_name.get(), e_phone.get())
clear_entries()
tkMessageBox.showinfo("Success", "Contact updated")
except ValueError as e:
tkMessageBox.showerror("Error", e)
def ask_delete_contact():
try:
contacts.delete_contact(e_name.get())
clear_entries()
tkMessageBox.showinfo("Success", "Contact deleted")
except ValueError as e:
tkMessageBox.showerror("Error", e)
def ask_list_contacts():
global tl
b_l.config(text="Close List", command=on_tl_exit)
tl = Toplevel(root)
tl.bind('<Destroy>', on_tl_exit)
scrollbar = Scrollbar(tl)
scrollbar.pack(side=RIGHT, fill=Y)
lb = Listbox(tl)
lb.pack()
lb.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=lb.yview)
for name, phone in contacts.list_contacts():
lb.insert(0, "{}:{}".format(name, phone))
def on_tl_exit(_=None):
b_l.config(text="Show All", command=ask_list_contacts)
tl.destroy()
def on_exit():
contacts.save_contacts()
root.quit()
Button(root, text="Add", width=10, command=ask_create_contact).grid(row=0, column=2)
Button(root, text="Find", width=10, command=ask_find_contact).grid(row=1, column=2)
Button(root, text="Update", width=10, command=ask_update_contact).grid(row=2, column=2)
Button(root, text="Delete", width=10, command=ask_delete_contact).grid(row=3, column=2)
b_l = Button(root, text="Show All", width=10, command=ask_list_contacts)
b_l.grid(row=3, column=0)
root.protocol("WM_DELETE_WINDOW", on_exit)
root.mainloop()