-
Notifications
You must be signed in to change notification settings - Fork 0
/
prac_10c.py
94 lines (75 loc) · 2.97 KB
/
prac_10c.py
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
from tkinter import *
import tkinter.messagebox as MessageBox
import mysql.connector
con = mysql.connector.connect(
host="localhost",
user="root",
password="",
database ="tk_projectdb"
)
cursor=con.cursor()
def submit():
name = e_name.get();
phone = e_phone.get();
gender = e_gender.get();
uid = e_uid.get();
if(name=="" or phone=="" or gender=="" or uid==""):
MessageBox.showinfo("Insert Status", "All Field Required")
else:
cursor.execute('INSERT INTO student (uname,phone,gender,uuid) VALUES(%s, %s, %s, %s)',(name,phone,gender,uid))
cursor.execute("commit");
MessageBox.showinfo("Submit Status", "Submitted Successfully");
def update():
name = e_name.get();
phone = e_phone.get();
gender = e_gender.get();
uid = e_uid.get();
if(name=="" or phone=="" or gender=="" or uid==""):
MessageBox.showinfo("Insert Status", "All Field Required")
else:
cursor.execute("SELECT * FROM student WHERE phone = '%s'" %(phone))
catch1 = cursor.fetchone()
print(catch1)
if catch1 == None:
MessageBox.showerror("error","some error encountered")
else:
cursor.execute("UPDATE student set uname = '%s',phone = '%s',gender = '%s',uuid = '%s'WHERE phone = '%s'" %(name,phone,gender,uid,phone))
cursor.execute("commit");
MessageBox.showinfo("Submit Status", "Record Updated Successfully");
def delete():
phone = e_phone.get();
cursor.execute("SELECT * FROM student WHERE phone = '%s'" %(phone))
catch2 = cursor.fetchone()
print(catch2)
if catch2 == None:
MessageBox.showerror("error","some error encountered")
else:
cursor.execute("DELETE FROM student WHERE phone = '%s'" %phone)
cursor.execute("commit");
MessageBox.showinfo("Submit Status", "Data deleted Successfully");
root = Tk()
root.geometry("400x300");
root.title("Student Details");
name = Label(root, text='Enter Name',font=('bold',10))
name.place(x=20, y=30)
e_name = Entry()
e_name.place(x=150, y=30)
phone = Label(root, text='Enter phone',font=('bold',10))
phone.place(x=20, y=60)
e_phone = Entry()
e_phone.place(x=150, y=60)
gender = Label(root, text='Enter Gender',font=('bold',10))
gender.place(x=20, y=90)
e_gender = Entry()
e_gender.place(x=150, y=90)
uid = Label(root, text='Enter Uid',font=('bold',10))
uid.place(x=20, y=120)
e_uid = Entry()
e_uid.place(x=150, y=120)
submit = Button(root, text="submit", font=("italic", 10),bg="green", command=submit)
submit.place(x=20, y= 170)
delete = Button(root, text="delete", font=("italic", 10),bg="red", command=delete)
delete.place(x=80, y= 170)
update = Button(root, text="update", font=("italic", 10),bg="blue", command=update)
update.place(x=130, y= 170)
root.mainloop()