44import sqlite3
55from sqlite3 import Error
66from tkinter import *
7+ import tkinter .messagebox
78root = Tk ()
8- root .geometry ('700x370 ' )
9+ root .geometry ('600x370 ' )
910list_of_names = []
1011root .title ('AddressBook' )
1112Name = StringVar ()
@@ -39,13 +40,23 @@ def create_table(conn, create_table_sql):
3940 print (e )
4041 return
4142
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+
4252""" Create a new task (ie creating new row) for the given Name taking care of all conditions such as Name,phone no
4353cannot be empty ,phone no should be 10 digits and also if Name already exist,then it cannot be inerted
4454"""
4555def create_task ():
4656 sql = ''' INSERT INTO tasks(name,status_id)
4757 VALUES(?,?) '''
4858 if (Name .get () not in list_of_names ):
59+
4960 if ((Name .get ()== '' ) | (Number .get ()== '' ) | (len (Number .get ())!= 10 )):
5061 top = Toplevel (root )
5162 top .geometry ('180x100' )
@@ -56,7 +67,8 @@ def create_task():
5667 myLabel .pack ()
5768 mySubmitButton = Button (top , text = ' Back ' , command = top .destroy )
5869 mySubmitButton .pack ()
59- return
70+ return
71+ onClickAdded ()
6072 cur = conn .cursor ()
6173 cur .execute (sql , (Name .get (),Number .get ()))
6274 conn .commit ()
@@ -116,7 +128,8 @@ def delete_task():
116128 if ((Name .get () not in list_of_names ) | (Name .get ()== '' )):
117129 inputDialog = MyDialog (root )
118130 root .wait_window (inputDialog .top )
119- return
131+ return
132+ onClickDeleted ()
120133 sql = 'DELETE FROM tasks WHERE name=?'
121134 cur = conn .cursor ()
122135 cur .execute (sql , (Name .get (),))
@@ -127,14 +140,19 @@ def delete_task():
127140"""
128141def select_all_tasks ():
129142 r_set = conn .execute ('''SELECT * from tasks''' );
130- i = 0
143+ i = 0
144+ top = Toplevel (root )
145+ #top.geometry('300x300')
131146 for student in r_set :
132147 list_of_names .append (student [1 ])
133148 for j in range (len (student )):
134- e = Entry (root , width = 11 , fg = 'Gray20' )
149+ e = Entry (top , width = 11 , fg = 'Gray20' )
135150 e .grid (row = i , column = j )
136151 e .insert (END , student [j ])
137152 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])
138156'''
139157Getting the path of database and defining the table to be created
140158'''
@@ -185,15 +203,15 @@ def RESET():
185203'''
186204Creating UI for whole application
187205'''
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 )
199217root .mainloop ()
0 commit comments