-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup_page.py
113 lines (86 loc) · 5.25 KB
/
signup_page.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from pathlib import Path
from tkinter import *
from PIL import Image, ImageTk
from tkinter import ttk, messagebox
import pymysql
import credentials as cr
OUTPUT_PATH = Path(__file__).parent
ASSETS_PATH = OUTPUT_PATH / Path("./asserts")
def relative_to_assets(path: str) -> Path:
return ASSETS_PATH / Path(path)
class SignUp:
def __init__(self, root):
self.window = root
self.window.title("Sign Up")
self.window.geometry("1280x800+0+0")
self.window.config(bg="white")
self.bg_img = ImageTk.PhotoImage(file=relative_to_assets("pexels-paul-uchechukwu-246994638-22674729.jpg"))
background = Label(self.window, image=self.bg_img).place(x=0, y=0, relwidth=1, relheight=1)
frame = Frame(self.window, bg="white")
frame.place(x=400, y=150, width=550, height=550)
title1 = Label(frame, text="Sign Up", font=("times new roman", 25, "bold"), bg="white").place(x=20, y=10)
title2 = Label(frame, text="Join with us", font=("times new roman", 13), bg="white", fg="gray").place(x=20, y=50)
f_name = Label(frame, text="First name", font=("helvetica", 15, "bold"), bg="white").place(x=20, y=100)
l_name = Label(frame, text="Last name", font=("helvetica", 15, "bold"), bg="white").place(x=240, y=100)
self.fname_txt = Entry(frame, font=("arial"))
self.fname_txt.place(x=20, y=130, width=200)
self.lname_txt = Entry(frame, font=("arial"))
self.lname_txt.place(x=240, y=130, width=200)
email = Label(frame, text="Email", font=("helvetica", 15, "bold"), bg="white").place(x=20, y=180)
self.email_txt = Entry(frame, font=("arial"))
self.email_txt.place(x=20, y=210, width=420)
sec_question = Label(frame, text="Security questions", font=("helvetica", 15, "bold"), bg="white").place(x=20, y=260)
answer = Label(frame, text="Answer", font=("helvetica", 15, "bold"), bg="white").place(x=240, y=260)
self.questions = ttk.Combobox(frame, font=("helvetica", 13), state='readonly', justify=CENTER)
self.questions['values'] = ("Select", "What's your pet name?", "Your first teacher name", "Your birthplace", "Your favorite movie")
self.questions.place(x=20, y=290, width=200)
self.questions.current(0)
self.answer_txt = Entry(frame, font=("arial"))
self.answer_txt.place(x=240, y=290, width=200)
password = Label(frame, text="New password", font=("helvetica", 15, "bold"), bg="white").place(x=20, y=340)
self.password_txt = Entry(frame, font=("arial"))
self.password_txt.place(x=20, y=370, width=420)
self.terms = IntVar()
terms_and_con = Checkbutton(frame, text="I Agree The Terms & Conditions", variable=self.terms, onvalue=1, offvalue=0, bg="white", font=("times new roman", 12)).place(x=20, y=420)
self.signup = Button(frame, text="Sign Up", command=self.signup_func, font=("times new roman", 19, "bold"), bd=0, cursor="hand2", bg="light grey", fg="black").place(x=120, y=470, width=250)
def signup_func(self):
if self.fname_txt.get() == "" or self.lname_txt.get() == "" or self.email_txt.get() == "" or self.questions.get() == "Select" or self.answer_txt.get() == "" or self.password_txt.get() == "":
messagebox.showerror("Error!", "Sorry!, All fields are required", parent=self.window)
elif self.terms.get() == 0:
messagebox.showerror("Error!", "Please Agree with our Terms & Conditions", parent=self.window)
else:
try:
connection = pymysql.connect(host=cr.host, user=cr.user, password=cr.password, database=cr.database)
cur = connection.cursor()
cur.execute("select * from user_register where email=%s", self.email_txt.get())
row = cur.fetchone()
# Check if the entered email id already exists or not.
if row is not None:
messagebox.showerror("Error!", "The email id already exists, please try again with another email id", parent=self.window)
else:
cur.execute("insert into user_register (f_name, l_name, email, question, answer, password) values(%s, %s, %s, %s, %s, %s)",
(
self.fname_txt.get(),
self.lname_txt.get(),
self.email_txt.get(),
self.questions.get(),
self.answer_txt.get(),
self.password_txt.get()
))
connection.commit()
connection.close()
messagebox.showinfo("Congratulations!", "Register Successful", parent=self.window)
self.reset_fields()
except Exception as es:
messagebox.showerror("Error!", f"Error due to {es}", parent=self.window)
def reset_fields(self):
self.fname_txt.delete(0, END)
self.lname_txt.delete(0, END)
self.email_txt.delete(0, END)
self.questions.current(0)
self.answer_txt.delete(0, END)
self.password_txt.delete(0, END)
if __name__ == "__main__":
root = Tk()
obj = SignUp(root)
root.mainloop()