|
| 1 | +from tkinter import * |
| 2 | +from PIL import Image, ImageTk |
| 3 | +from tkinter import ttk, messagebox |
| 4 | +import pymysql, os |
| 5 | +import os |
| 6 | + |
| 7 | + |
| 8 | +import credentials as cr |
| 9 | + |
| 10 | +class SignUp: |
| 11 | +def __init__(self, root): |
| 12 | +self.root = root |
| 13 | +self.root.title("Sign Up") |
| 14 | +self.root.geometry("1280x800+0+0") |
| 15 | +self.root.config(bg = "white") |
| 16 | + |
| 17 | +self.bg_img = ImageTk.PhotoImage(file="Images/wallpaperbetter.jpg") |
| 18 | +background = Label(self.root,image=self.bg_img).place(x=0,y=0,relwidth=1,relheight=1) |
| 19 | + |
| 20 | + |
| 21 | +frame = Frame(self.root, bg="white") |
| 22 | +frame.place(x=350,y=100,width=500,height=550) |
| 23 | + |
| 24 | +title1 = Label(frame, text="Sign Up", font=("times new roman",25,"bold"),bg="white").place(x=20, y=10) |
| 25 | +title2 = Label(frame, text="Join with us", font=("times new roman",13),bg="white", fg="gray").place(x=20, y=50) |
| 26 | + |
| 27 | +f_name = Label(frame, text="First name", font=("helvetica",15,"bold"),bg="white").place(x=20, y=100) |
| 28 | +l_name = Label(frame, text="Last name", font=("helvetica",15,"bold"),bg="white").place(x=240, y=100) |
| 29 | + |
| 30 | +self.fname_txt = Entry(frame,font=("arial")) |
| 31 | +self.fname_txt.place(x=20, y=130, width=200) |
| 32 | + |
| 33 | +self.lname_txt = Entry(frame,font=("arial")) |
| 34 | +self.lname_txt.place(x=240, y=130, width=200) |
| 35 | + |
| 36 | +email = Label(frame, text="Email", font=("helvetica",15,"bold"),bg="white").place(x=20, y=180) |
| 37 | + |
| 38 | +self.email_txt = Entry(frame,font=("arial")) |
| 39 | +self.email_txt.place(x=20, y=210, width=420) |
| 40 | + |
| 41 | +sec_question = Label(frame, text="Security questions", font=("helvetica",15,"bold"),bg="white").place(x=20, y=260) |
| 42 | +answer = Label(frame, text="Answer", font=("helvetica",15,"bold"),bg="white").place(x=240, y=260) |
| 43 | + |
| 44 | +self.questions = ttk.Combobox(frame,font=("helvetica",13),state='readonly',justify=CENTER) |
| 45 | +self.questions['values'] = ("Select","What's your pet name?","Your first teacher name","Your birthplace", "Your favorite movie") |
| 46 | +self.questions.place(x=20,y=290,width=200) |
| 47 | +self.questions.current(0) |
| 48 | + |
| 49 | +self.answer_txt = Entry(frame,font=("arial")) |
| 50 | +self.answer_txt.place(x=240, y=290, width=200) |
| 51 | + |
| 52 | +password = Label(frame, text="New password", font=("helvetica",15,"bold"),bg="white").place(x=20, y=340) |
| 53 | + |
| 54 | +self.password_txt = Entry(frame,font=("arial")) |
| 55 | +self.password_txt.place(x=20, y=370, width=420) |
| 56 | + |
| 57 | +self.terms = IntVar() |
| 58 | +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) |
| 59 | +self.signup = Button(frame,text="Sign Up",command=self.signup_func,font=("times new roman",18, "bold"),bd=0,cursor="hand2",bg="green2",fg="white").place(x=120,y=460,width=250) |
| 60 | +self.loginbt1 = Button(frame, text="Login page", command=self.log1, font=("times new roman", 18, "bold"), bd=0,cursor="hand2", bg="green2", fg="white").place(x=120, y=510, width=250) |
| 61 | +def signup_func(self): |
| 62 | +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() == "": |
| 63 | +messagebox.showerror("Error!","Sorry!, All fields are required",parent=self.root) |
| 64 | + |
| 65 | +elif self.terms.get() == 0: |
| 66 | +messagebox.showerror("Error!","Please Agree with our Terms & Conditions",parent=self.root) |
| 67 | + |
| 68 | +else: |
| 69 | +try: |
| 70 | +connection = pymysql.connect(host="localhost", user="root", password="chirag123", database="hospitals") |
| 71 | +cur = connection.cursor() |
| 72 | +cur.execute("select * from user_register where email=%s",self.email_txt.get()) |
| 73 | +row=cur.fetchone() |
| 74 | + |
| 75 | +# Check if th entered email id is already exists or not. |
| 76 | +if row!=None: |
| 77 | +messagebox.showerror("Error!","The email id is already exists, please try again with another email id",parent=self.root) |
| 78 | +else: |
| 79 | +cur.execute("insert into user_register (f_name,l_name,email,question,answer,password) values(%s,%s,%s,%s,%s,%s)", |
| 80 | +( |
| 81 | +self.fname_txt.get(), |
| 82 | +self.lname_txt.get(), |
| 83 | +self.email_txt.get(), |
| 84 | +self.questions.get(), |
| 85 | +self.answer_txt.get(), |
| 86 | +self.password_txt.get() |
| 87 | +)) |
| 88 | +connection.commit() |
| 89 | +connection.close() |
| 90 | +messagebox.showinfo("Congratulations!","Register Successful",parent=self.root) |
| 91 | +self.reset_fields() |
| 92 | +except Exception as e: |
| 93 | +messagebox.showerror("Error!",f"Error due to {str(e)}",parent=self.root) |
| 94 | + |
| 95 | +def reset_fields(self): |
| 96 | +self.fname_txt.delete(0, END) |
| 97 | +self.lname_txt.delete(0, END) |
| 98 | +self.email_txt.delete(0, END) |
| 99 | +self.questions.current(0) |
| 100 | +self.answer_txt.delete(0, END) |
| 101 | +self.password_txt.delete(0, END) |
| 102 | + |
| 103 | +def log1(self): |
| 104 | +self.root.destroy() |
| 105 | +os.system("login_page.py") |
| 106 | + |
| 107 | + |
| 108 | +if __name__ == "__main__": |
| 109 | +root = Tk() |
| 110 | +obj = SignUp(root) |
| 111 | +root.mainloop() |
0 commit comments