-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegistrationWindow.py
More file actions
138 lines (94 loc) · 5.05 KB
/
RegistrationWindow.py
File metadata and controls
138 lines (94 loc) · 5.05 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from tkinter import *
from PIL import Image,ImageTk
from tkinter import messagebox
import re,pymysql
root = Tk()
root.title("Welcome!!")
root.geometry("1350x700+0+0")
root.iconbitmap("C:\\Users\\apoor\\Desktop\\Tkinter\\logo.ico")
def loginWindow():
root.destroy()
import loginWindow
def registerData():
if(Name.get() == "" or lName.get() == ""
or Email.get() == "" or password.get() == "" or confirmpassword.get() == "" or contact.get() == ""):
messagebox.showerror("Error","All fields are required!", parent=root)
elif(checkValidEmailorNot(Email.get()) == 0):
messagebox.showerror("Error","Invalid email address", parent=root)
elif(password.get() != confirmpassword.get()):
messagebox.showerror("Error","Passwords don't match!", parent=root)
elif(isValidPhone(contact.get()) == 0):
messagebox.showerror("Error","Invalid contact number", parent=root)
else:
try:
conn = pymysql.connect(host="localhost", user="root", password="",database="students")
cursor = conn.cursor()
cursor.execute("SELECT * FROM studentregistration where email=%s", Email.get())
row = cursor.fetchone()
if(row != None):
messagebox.showerror("Error","User already exists!", parent=root)
else:
cursor.execute("INSERT INTO studentregistration (fname, lname, contact,email,password) values(%s, %s, %s, %s, %s)",
(Name.get(),
lName.get(),
contact.get(),
Email.get(),
password.get()
))
conn.commit()
conn.close()
messagebox.showinfo("Success","Registration Successfull!", parent=root)
clearFields()
except Exception as E:
messagebox.showerror("Error",f"Due to {str(E)}", parent=root)
def checkValidEmailorNot(email):
regex = '^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$'
if(re.search(regex, email)):
return(1)
else:
return(0)
def isValidPhone(number):
pattern = '^[7-9][0-9]{9}$'
if(re.search(pattern, number)):
return(1)
else:
return(0)
def clearFields():
Name.delete(0, END)
lName.delete(0, END)
Email.delete(0, END)
contact.delete(0, END)
password.delete(0 ,END)
confirmpassword.delete(0, END)
# Frame
frame = Frame(root, bg="white")
frame.place(x=420,y=30,width=920, height=580)
frame1 = Frame(root, bg="grey")
frame1.place(x=0,y=0, width=415, height=800)
# Login Area
LImage = ImageTk.PhotoImage(file="C:\\Users\\apoor\\Desktop\\Tkinter\\logo1.jpg")
LLabel = Label(root, image=LImage).place(x=10,y=30)
login_image = ImageTk.PhotoImage(file="C:\\Users\\apoor\\Desktop\\Tkinter\\loginBtn.png")
btn1 = Button(frame1, image=login_image,bd=0,cursor="hand2", command=loginWindow).place(x=100,y=300)
title = Label(frame, text="REGISTER HERE",font=("times new roman",16,"bold"), bg="white", fg="green").place(x=50,y=30)
first_name = Label(frame, text="First Name",font=("times new roman",12,"bold"), bg="white", fg="gray").place(x=50,y=90)
Name = Entry(frame, width=26, borderwidth=5, font=("times new roman",14),bg="#E0E0E0")
Name.place(x=50, y=120)
last_name = Label(frame, text="Last Name",font=("times new roman",12,"bold"), bg="white", fg="gray").place(x=500,y=90)
lName = Entry(frame, width=26, borderwidth=5, font=("times new roman",14),bg="#E0E0E0")
lName.place(x=500, y=120)
email = Label(frame, text="Email address",font=("times new roman",12,"bold"), bg="white", fg="gray").place(x=50,y=220)
Email = Entry(frame, borderwidth=5, font=("times new roman",14),bg="#E0E0E0")
Email.place(x=50, y=250,width=250)
password = Label(frame, text="Password",font=("times new roman",12,"bold"), bg="white", fg="gray").place(x=500,y=220)
password = Entry(frame, borderwidth=5, font=("times new roman",14),bg="#E0E0E0")
password.place(x=500, y=250,width=250)
cpassword = Label(frame, text="Confirm Password",font=("times new roman",12,"bold"), bg="white", fg="gray").place(x=50,y=360)
confirmpassword = Entry(frame, borderwidth=5, font=("times new roman",14),bg="#E0E0E0")
confirmpassword.place(x=50, y=390,width=250)
contact = Label(frame, text="Contact Number",font=("times new roman",12,"bold"), bg="white", fg="gray").place(x=500,y=360)
contact = Entry(frame, borderwidth=5, font=("times new roman",14),bg="#E0E0E0")
contact.place(x=500, y=390,width=250)
tn_image = ImageTk.PhotoImage(file="C:\\Users\\apoor\\Desktop\\Tkinter\\registernow.png")
btn = Button(frame, image=tn_image,bd=0,cursor="hand2", command=registerData).place(x=50,y=460)
root.mainloop()