4
4
import sqlite3
5
5
from sqlite3 import Error
6
6
from tkinter import *
7
+ import tkinter .messagebox
7
8
root = Tk ()
8
- root .geometry ('700x370 ' )
9
+ root .geometry ('600x370 ' )
9
10
list_of_names = []
10
11
root .title ('AddressBook' )
11
12
Name = StringVar ()
@@ -39,13 +40,23 @@ def create_table(conn, create_table_sql):
39
40
print (e )
40
41
return
41
42
43
+ '''
44
+ displaying added/deleted message
45
+ '''
46
+ def onClickAdded ():
47
+ tkinter .messagebox .showinfo (" " ,Name .get ()+ " got added" )
48
+
49
+ def onClickDeleted ():
50
+ tkinter .messagebox .showinfo (" " ,Name .get ()+ " got deleted" )
51
+
42
52
""" Create a new task (ie creating new row) for the given Name taking care of all conditions such as Name,phone no
43
53
cannot be empty ,phone no should be 10 digits and also if Name already exist,then it cannot be inerted
44
54
"""
45
55
def create_task ():
46
56
sql = ''' INSERT INTO tasks(name,status_id)
47
57
VALUES(?,?) '''
48
58
if (Name .get () not in list_of_names ):
59
+
49
60
if ((Name .get ()== '' ) | (Number .get ()== '' ) | (len (Number .get ())!= 10 )):
50
61
top = Toplevel (root )
51
62
top .geometry ('180x100' )
@@ -56,7 +67,8 @@ def create_task():
56
67
myLabel .pack ()
57
68
mySubmitButton = Button (top , text = ' Back ' , command = top .destroy )
58
69
mySubmitButton .pack ()
59
- return
70
+ return
71
+ onClickAdded ()
60
72
cur = conn .cursor ()
61
73
cur .execute (sql , (Name .get (),Number .get ()))
62
74
conn .commit ()
@@ -116,7 +128,8 @@ def delete_task():
116
128
if ((Name .get () not in list_of_names ) | (Name .get ()== '' )):
117
129
inputDialog = MyDialog (root )
118
130
root .wait_window (inputDialog .top )
119
- return
131
+ return
132
+ onClickDeleted ()
120
133
sql = 'DELETE FROM tasks WHERE name=?'
121
134
cur = conn .cursor ()
122
135
cur .execute (sql , (Name .get (),))
@@ -127,14 +140,19 @@ def delete_task():
127
140
"""
128
141
def select_all_tasks ():
129
142
r_set = conn .execute ('''SELECT * from tasks''' );
130
- i = 0
143
+ i = 0
144
+ top = Toplevel (root )
145
+ #top.geometry('300x300')
131
146
for student in r_set :
132
147
list_of_names .append (student [1 ])
133
148
for j in range (len (student )):
134
- e = Entry (root , width = 11 , fg = 'Gray20' )
149
+ e = Entry (top , width = 11 , fg = 'Gray20' )
135
150
e .grid (row = i , column = j )
136
151
e .insert (END , student [j ])
137
152
i = i + 1
153
+ okButton = Button (top , text = ' ok ' , command = top .destroy )
154
+ okButton .grid (row = i + 3 , column = j - 1 )
155
+ #okButton.insert(END, student[j])
138
156
'''
139
157
Getting the path of database and defining the table to be created
140
158
'''
@@ -185,15 +203,15 @@ def RESET():
185
203
'''
186
204
Creating UI for whole application
187
205
'''
188
- Label (root , text = 'NAME' , font = 'Times 15 bold' ).place (x = 230 , y = 20 )
189
- Entry (root , textvariable = Name ,width = 42 ).place (x = 300 , y = 25 )
190
- Label (root , text = 'PHONE NO ' , font = 'Times 15 bold' ).place (x = 230 , y = 70 )
191
- Entry (root , textvariable = Number ,width = 35 ).place (x = 342 , y = 73 )
192
- Button (root ,text = " ADD" , font = 'Times 14 bold' ,bg = 'dark gray' , command = create_task ,width = 8 ).place (x = 230 , y = 110 )
193
- Button (root ,text = "EDIT" , font = 'Times 14 bold' ,bg = 'dark gray' ,command = update_task ,width = 8 ).place (x = 360 , y = 108 )
194
- Button (root ,text = "DELETE" , font = 'Times 14 bold' ,bg = 'dark gray' ,command = delete_task ,width = 8 ).place (x = 490 , y = 107.5 )
195
- Button (root ,text = "VIEW ALL" , font = 'Times 14 bold' ,bg = 'dark gray' , command = select_all_tasks ,width = 12 ).place (x = 260 , y = 191 )
196
- Button (root ,text = "VIEW BY NAME" , font = 'Times 14 bold' ,bg = 'dark gray' , command = select_task_by_name ,width = 13 ).place (x = 430 , y = 190 )
197
- Button (root ,text = "EXIT" , font = 'Times 14 bold' ,bg = 'dark gray' , command = EXIT ,width = 8 ).place (x = 300 , y = 280 )
198
- Button (root ,text = "RESET" , font = 'Times 14 bold' ,bg = 'dark gray' , command = RESET ,width = 8 ).place (x = 420 , y = 280 )
206
+ Label (root , text = 'NAME' , font = 'Times 15 bold' ).place (x = 130 , y = 20 )
207
+ Entry (root , textvariable = Name ,width = 42 ).place (x = 200 , y = 25 )
208
+ Label (root , text = 'PHONE NO ' , font = 'Times 15 bold' ).place (x = 130 , y = 70 )
209
+ Entry (root , textvariable = Number ,width = 35 ).place (x = 242 , y = 73 )
210
+ Button (root ,text = " ADD" , font = 'Times 14 bold' ,bg = 'dark gray' , command = create_task ,width = 8 ).place (x = 130 , y = 110 )
211
+ Button (root ,text = "EDIT" , font = 'Times 14 bold' ,bg = 'dark gray' ,command = update_task ,width = 8 ).place (x = 260 , y = 108 )
212
+ Button (root ,text = "DELETE" , font = 'Times 14 bold' ,bg = 'dark gray' ,command = delete_task ,width = 8 ).place (x = 390 , y = 107.5 )
213
+ Button (root ,text = "VIEW ALL" , font = 'Times 14 bold' ,bg = 'dark gray' , command = select_all_tasks ,width = 12 ).place (x = 160 , y = 191 )
214
+ Button (root ,text = "VIEW BY NAME" , font = 'Times 14 bold' ,bg = 'dark gray' , command = select_task_by_name ,width = 13 ).place (x = 330 , y = 190 )
215
+ Button (root ,text = "EXIT" , font = 'Times 14 bold' ,bg = 'dark gray' , command = EXIT ,width = 8 ).place (x = 200 , y = 280 )
216
+ Button (root ,text = "RESET" , font = 'Times 14 bold' ,bg = 'dark gray' , command = RESET ,width = 8 ).place (x = 320 , y = 280 )
199
217
root .mainloop ()
0 commit comments