-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmySQL_Python.py
More file actions
122 lines (102 loc) · 3.32 KB
/
Copy pathmySQL_Python.py
File metadata and controls
122 lines (102 loc) · 3.32 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from tkinter import *
import mysql.connector
expression = ""
connection = mysql.connector.connect(
host="localhost", user="root", passwd="root", database="2020btecs00040")
curser = connection.cursor()
root = Tk()
root.geometry('500x400')
root.title("Student Registration System")
def add_course(): # new window definition
def add_query():
global root
statement = "INSERT INTO STUDENT VALUES ('" + \
E1.get()+"','"+E2.get()+"')"
curser.execute(statement)
connection.commit()
add.config(state=NORMAL)
update.config(state=NORMAL)
show.config(state=NORMAL)
delete.config(state=NORMAL)
newwin.destroy()
newwin = Toplevel(root)
newwin.geometry('400x300')
add.config(state=DISABLED)
newwin.title("Add New Student")
L1 = Label(newwin, text="Student Name")
L1.place(x=10, y=50)
E1 = Entry(newwin, bd=5)
E1.place(x=100, y=50)
L2 = Label(newwin, text="PRN")
L2.place(x=10, y=100)
E2 = Entry(newwin, bd=5)
E2.place(x=100, y=100)
button = Button(newwin, text="Add", command=add_query)
button.place(x=120, y=200)
def update_data(): # new window definition
def update_query():
global root
statement = "UPDATE STUDENT SET NAME = '" + \
E1.get()+"' WHERE PRN ='"+E2.get()+"'"
curser.execute(statement)
connection.commit()
add.config(state=NORMAL)
newwin.destroy()
newwin = Toplevel(root)
newwin.geometry('400x300')
newwin.title("Update Student")
add.config(state=NORMAL)
L1 = Label(newwin, text="Student Name")
L1.place(x=10, y=50)
E1 = Entry(newwin, bd=5)
E1.place(x=100, y=50)
L2 = Label(newwin, text="PRN")
L2.place(x=10, y=100)
E2 = Entry(newwin, bd=5)
E2.place(x=100, y=100)
button = Button(newwin, text="Update", command=update_query)
button.place(x=120, y=200)
def del_data():
def delete_query():
global root
statement = "DELETE FROM STUDENT WHERE PRN='"+E1.get()+"'"
curser.execute(statement)
connection.commit()
add.config(state=NORMAL)
newwin.destroy()
newwin = Toplevel(root)
newwin.geometry('400x300')
newwin.title("Delete Student")
add.config(state=NORMAL)
L1 = Label(newwin, text="PRN")
L1.place(x=10, y=50)
E1 = Entry(newwin, bd=5)
E1.place(x=100, y=50)
sub = Button(newwin, text="Delete Student", command=delete_query)
sub.place(x=120, y=200)
def display():
newwin = Toplevel(root)
newwin.geometry('400x300')
newwin.title("Student Details")
statement = "SELECT * FROM STUDENT"
curser.execute(statement)
L1 = Label(newwin, text="Student Name")
L1.grid(row=0, column=0)
L2 = Label(newwin, text="PRN")
L2.grid(row=0, column=1)
i = 1
for row in curser:
L1 = Label(newwin, text=row[0])
L1.grid(row=i, column=0)
L2 = Label(newwin, text=row[1])
L2.grid(row=i, column=1)
i += 1
add = Button(root, text='Add New Student', command=add_course)
delete = Button(root, text='Delete Student', command=del_data)
update = Button(root, text='Update Student', command=update_data)
show = Button(root, text='View Details', command=display)
add.place(x=80, y=80)
delete.place(x=80, y=150)
update.place(x=250, y=80)
show.place(x=250, y=150)
root.mainloop()