These Are The Records in Employee Table Before Update: 34 - KAMALA - 55 - Female - PHD - 1000000.0 - Professor - 02-05-1990
These Are The Records in Employee Table Before Update: 34 - KAMALA - 55 - Female - PHD - 1000000.0 - Professor - 02-05-1990
C:\sqlite3>sqlite3 my3.db
1|ram|22|male|MTECH|30000.0|Assistant professor|02-02-1988
5|suma|30|female|MTECH|1000.0|Assistant professor|03-01-1999
9|GAYATHRI|23|female|BE|10000.0|Assistant professor|02-01-2016
123|SACHIN|18|male|MTECH|20000.0|Assistant professor|01-01-2003
34|KAMALA|55|female|PHD|1000000.0|professor|02-05-1990
38|KAVERI|55|female|PHD|100000.0|professor|02-03-1990
78|SUHAS|27|male|BE|7000.0|Assistant professor|03-08-2017
576|gfh|18|female|MTECH|123.0|Assistant professor|01-01-2000
63|shivu|30|male|MTECH|30000.0|Assocaite professor|02-02-2013
678|padamini|26|female|BE|3000.0|Assistant professor|05-01-2019
900|RAGHU|26|male|BE|10000.0|Assistant professor|03-04-2001
11111|JHKJ|19|male|SSLC|2000.0|peon|01-01-2000
777|HKLJL|19|female|BE|1000.0|Assistant professor|01-01-2000
sqlite>
#python program to UDATE a record of employee table and display the rcords before and after update
#using GUI
import sqlite3
def raise_frame(frame):
#when update button is selected second frame is raised which allows user to update
#record. First select empid from spinbox and press mouse right button
if frame==f1:
frame.tkraise()
l1=Label(f1,text="select Empid").place(x=50,y=200)
v1=IntVar()
le=[]
conn = sqlite3.connect('c:\sqlite3\my3.db')
c = conn.cursor()
for i in r1:
le.append(int(i[0]))
conn.close()
te=tuple(le)
s1=Spinbox(f1,font=('Arial',14),value=te, textvariable=v1,width=3)
s1.place(x=200,y=200)
l4=Label(f1,text="Old Salary",font=('Arial',14)).place(x=550,y=100)
t=Text(f1,width=25,height=2)
t.place(x=650,y=100)
s9=DoubleVar()
e3=Entry(f1,width=20,font=('Arial',14),textvariable=s9)
e3.place(x=650,y=150)
def show1(self):
eid=int(v1.get())
conn1 = sqlite3.connect('c:\sqlite3\my3.db')
c1 = conn1.cursor()
r3=c1.execute(sql,(eid,))
for i in r3:
t.insert(END,i[0])
conn1.close()
def show2(self):
new=s9.get()
new=float(new)
print(new)
if new!=0.0:
conn2 = sqlite3.connect('c:\sqlite3\my3.db')
c2 = conn2.cursor()
c2.execute(sql1,(new,eid))
conn2.commit()
if c2.rowcount==1:
conn2.close()
else:
#once new salary is entered in entry press enter key to call show2 function
e3.bind("<Return>",show2)
#once spinbox item is selected press right button to invoke show1 fucnction
s1.bind("<Button-3>",show1)
if frame==f:
frame.tkraise()
if frame==f2:
frame.tkraise()
l10.place(x=50,y=10)
t=Text(f2,width=70,height=15,wrap=WORD)
t.place(x=200,y=100)
conn3 = sqlite3.connect('c:\sqlite3\my3.db')
c3 = conn3.cursor()
r=c3.execute("select * from employee")
for i in r:
t.insert(END,i)
t.insert(END,'\n')
conn3.close()
r=Tk()
r.geometry('1000x1000')
f=Frame(r,width=1000,height=1000)
f.place(x=20,y=20)
f1=Frame(r,width=1000,height=1000)
f1.place(x=20,y=20)
f2=Frame(r,width=1000,height=1000)
f2.place(x=20,y=20)
#on clicking update button it opens new form where by selecting empid salary of that employee can be
updated
#on clicking display button it display button display the current records in employee table
b=Button(f,text="UDATE",font=('Arial',20,'bold'),fg='red',command=lambda:raise_frame(f1)).place(x=40
0,y=50)
b1=Button(f,text="DISPLAY",font=('Arial',20,'bold'),fg='red',command=lambda:raise_frame(f2)).place(x=
400,y=150)
b2=Button(f1,text="BACK",font=('Arial',20,'bold'),fg='red',command=lambda:raise_frame(f)).place(x=55
0,y=550)
b3=Button(f2,text="BACK",font=('Arial',20,'bold'),fg='red',command=lambda:raise_frame(f)).place(x=55
0,y=550)
raise_frame(f)
r.mainloop()
Output:
Select empid press right button, then current salary will be displayed in text box and enter new salary in
entry widget and press enter button,u will get message record is inserted successfuly
Press back button to link back to home page
1|ram|22|male|MTECH|30000.0|Assistant professor|02-02-1988
5|suma|30|female|MTECH|1000.0|Assistant professor|03-01-1999
9|GAYATHRI|23|female|BE|10000.0|Assistant professor|02-01-2016
123|SACHIN|18|male|MTECH|20000.0|Assistant professor|01-01-2003
34|KAMALA|55|female|PHD|6000.0|professor|02-05-1990
38|KAVERI|55|female|PHD|100000.0|professor|02-03-1990
78|SUHAS|27|male|BE|7000.0|Assistant professor|03-08-2017
576|gfh|18|female|MTECH|123.0|Assistant professor|01-01-2000
63|shivu|30|male|MTECH|30000.0|Assocaite professor|02-02-2013
678|padamini|26|female|BE|3000.0|Assistant professor|05-01-2019
900|RAGHU|26|male|BE|10000.0|Assistant professor|03-04-2001
11111|JHKJ|19|male|SSLC|2000.0|peon|01-01-2000
777|HKLJL|19|female|BE|1000.0|Assistant professor|01-01-2000
34|KAMALA|55|female|PHD|6000.0|professor|02-05-1990