-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdd_Student.py
55 lines (52 loc) · 2.38 KB
/
Add_Student.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
from tkinter import *
from tkinter import messagebox
import re
from tkinter import ttk
import mysql.connector
from mysql.connector import Error
import os,sys
py=sys.executable
#creating window
class reg(Tk):
def __init__(self):
super().__init__()
self.iconbitmap(r"import your favicon.ico path")
self.maxsize(500, 417)
self.minsize(500, 417)
self.title('Add User')
self.canvas = Canvas(width=500, height=417, bg='gray')
self.canvas.pack()
#creating variables Please chech carefully
u = StringVar()
n = StringVar()
p = StringVar()
def insert():
try:
self.conn = mysql.connector.connect(host='localhost',
database='database_name',
user='username',
password='user password')
self.myCursor = self.conn.cursor()
self.myCursor.execute("Insert into admin(user,name,password) values (%s,%s,%s)",[u.get(), n.get(), p.get()])
self.conn.commit()
messagebox.showinfo("Done", "User Inserted Successfully")
ask = messagebox.askyesno("Confirm", "Do you want to add another user?")
if ask:
self.destroy()
os.system('%s %s' % (py, 'Add_Student.py'))
else:
self.destroy()
self.myCursor.close()
self.conn.close()
except Error:
messagebox.showinfo("Error", "Something Goes Wrong")
#label and input
Label(self, text='User Details', bg='gray', fg='black', font=('Courier new', 25, 'bold')).place(x=130, y=22)
Label(self, text='Username:', bg='gray', font=('Courier new', 10, 'bold')).place(x=70, y=82)
Entry(self, textvariable=u, width=30).place(x=200, y=84)
Label(self, text='Name:', bg='gray', font=('Courier new', 10, 'bold')).place(x=70, y=130)
Entry(self, textvariable=n, width=30).place(x=200, y=132)
Label(self, text='Password:', bg='gray', font=('Courier new', 10, 'bold')).place(x=70, y=180)
Entry(self, textvariable=p, width=30).place(x=200, y=182)
Button(self, text="Submit", width=15, command=insert).place(x=230, y=220)
reg().mainloop()