REGISTRATION AND LOGIN FORM WITH SQL DATABASE USING PYTHON
Source Code:-
Registration Page Code
01 02 03 04 05 06 07 08 09 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 | # Required Module-1 :- pip install tk # Required Module-2 :- pip install mysql-connector-python from tkinter import * from tkinter import messagebox as msg import mysql.connector root = Tk() root.title( "REGISTRATION FORM" ) root.geometry( "650x530+350+50" ) root.config(bg = "#259985" ) db = mysql.connector.connect( host = "localhost" , user = "root" , password = "Enter your password" , database = "register" ) cur = db.cursor() def data(): Name = name.get() DOB = dob.get() Gender = gender.get() Email = email.get() Mobile = mob.get() Password = pswrd.get() if Name ! = " " and DOB != " " and Gender != " " and Email != " " and Mobile != " " and Password != " ": sql = f "insert into students(Name, DOB, Gender, Email, Mobile, Password) Values(%s, %s, %s, %s, %s, %s)" val = [(Name, DOB, Gender, Email, Mobile, Password)] cur.executemany(sql, val) db.commit() print (cur.rowcount, "record inserted." ) msg.showinfo( "Registered" , "Your Data Registered Successfully." ) else : msg.showerror( "Error" , "Please Fill all the Entries." ) def clear(): name. set ("") dob. set ("") gender. set ("") email. set ("") mob. set ("") pswrd. set ("") Label(text = "REGISTRATION FORM" , font = ( "None 35 bold underline" ), bg = "#259985" ).place(x = 80 , y = 0 ) Label(text = "Name:" , font = ( "None 25 bold" ), bg = "#259985" ).place(x = 90 , y = 100 ) name = StringVar() Entry(root, textvariable = name, font = ( "None 20 bold" ), width = 23 ).place(x = 260 , y = 105 ) Label(text = "DOB:" , font = ( "None 25 bold" ), bg = "#259985" ).place(x = 100 , y = 150 ) dob = StringVar() Entry(root, textvariable = dob, font = ( "None 20 bold" ), width = 23 ).place(x = 260 , y = 155 ) Label(text = "Gender:" , font = ( "None 25 bold" ), bg = "#259985" ).place(x = 80 , y = 200 ) gender = StringVar() Boy = Radiobutton(root, text = "Male" , variable = gender, value = "Male" , font = ( "None 25 bold" ), bg = "#259985" , activebackground = "#259985" ) Boy.place(x = 280 , y = 200 ) Girl = Radiobutton(root, text = "Female" , variable = gender, value = "Female" , font = ( "None 25 bold" ), bg = "#259985" , activebackground = "#259985" ) Girl.place(x = 440 , y = 200 ) Label(text = "Email:" , font = ( "None 25 bold" ), bg = "#259985" ).place(x = 95 , y = 250 ) email = StringVar() Entry(root, textvariable = email, font = ( "None 20 bold" ), width = 23 ).place(x = 260 , y = 255 ) Label(text = "Mobile:" , font = ( "None 25 bold" ), bg = "#259985" ).place(x = 85 , y = 300 ) mob = StringVar() Entry(root, textvariable = mob, font = ( "None 20 bold" ), width = 23 ).place(x = 260 , y = 305 ) Label(text = "Password:" , font = ( "None 25 bold" ), bg = "#259985" ).place(x = 60 , y = 350 ) pswrd = StringVar() Entry(root, textvariable = pswrd, font = ( "None 20 bold" ), width = 23 , show = "*" ).place(x = 260 , y = 355 ) B1 = Button(root, text = "Register" , font = ( "None 25 bold" ), bg = "#823799" , activebackground = "#823999" , relief = RAISED, bd = 5 , command = data) B1.place(x = 150 , y = 430 ) B1 = Button(root, text = "Clear" , font = ( "None 25 bold" ), bg = "tan2" , activebackground = "tan2" , relief = RAISED, bd = 5 , command = clear) B1.place(x = 400 , y = 430 ) root.mainloop() |
# Required Module-1 :- pip install tk
# Required Module-2 :- pip install mysql-connector-python
from tkinter import *
from tkinter import messagebox as msg
import mysql.connector
root = Tk()
root.title("REGISTRATION FORM")
root.geometry("650x530+350+50")
root.config(bg = "#259985")
db = mysql.connector.connect(
host="localhost",
user="root",
password="Enter your password",
database="register")
cur = db.cursor()
def data():
Name = name.get()
DOB = dob.get()
Gender = gender.get()
Email = email.get()
Mobile = mob.get()
Password = pswrd.get()
if Name != "" and DOB != "" and Gender != "" and Email != "" and Mobile != "" and Password != "":
sql = f"insert into students(Name, DOB, Gender, Email, Mobile, Password) Values(%s, %s, %s, %s, %s, %s)"
val = [(Name, DOB, Gender, Email, Mobile, Password)]
cur.executemany(sql, val)
db.commit()
print(cur.rowcount, "record inserted.")
msg.showinfo("Registered", "Your Data Registered Successfully.")
else:
msg.showerror("Error", "Please Fill all the Entries.")
def clear():
name.set("")
dob.set("")
gender.set("")
email.set("")
mob.set("")
pswrd.set("")
Label(text="REGISTRATION FORM", font=("None 35 bold underline"), bg = "#259985").place(x = 80, y = 0)
Label(text="Name:", font=("None 25 bold"), bg = "#259985").place(x = 90, y = 100)
name = StringVar()
Entry(root, textvariable=name, font=("None 20 bold"), width=23).place(x = 260, y = 105)
Label(text="DOB:", font=("None 25 bold"), bg = "#259985").place(x = 100, y = 150)
dob = StringVar()
Entry(root, textvariable=dob, font=("None 20 bold"), width=23).place(x = 260, y = 155)
Label(text="Gender:", font=("None 25 bold"), bg = "#259985").place(x = 80, y = 200)
gender = StringVar()
Boy = Radiobutton(root, text = "Male", variable = gender, value = "Male", font = ("None 25 bold"), bg = "#259985", activebackground = "#259985" )
Boy.place(x = 280, y = 200)
Girl = Radiobutton(root, text = "Female", variable = gender, value = "Female", font = ("None 25 bold"), bg = "#259985", activebackground = "#259985")
Girl.place(x = 440, y = 200)
Label(text="Email:", font=("None 25 bold"), bg = "#259985").place(x = 95, y = 250)
email = StringVar()
Entry(root, textvariable=email, font=("None 20 bold"), width=23).place(x = 260, y = 255)
Label(text="Mobile:", font=("None 25 bold"), bg = "#259985").place(x = 85, y = 300)
mob = StringVar()
Entry(root, textvariable=mob, font=("None 20 bold"), width=23).place(x = 260, y = 305)
Label(text="Password:", font=("None 25 bold"), bg = "#259985").place(x = 60, y = 350)
pswrd = StringVar()
Entry(root, textvariable=pswrd, font=("None 20 bold"), width=23, show="*").place(x = 260, y = 355)
B1 = Button(root, text="Register", font=("None 25 bold"), bg = "#823799", activebackground="#823999", relief=RAISED, bd = 5, command=data)
B1.place(x = 150, y = 430)
B1 = Button(root, text="Clear", font=("None 25 bold"), bg = "tan2", activebackground="tan2", relief=RAISED, bd = 5, command=clear)
B1.place(x = 400, y = 430)
root.mainloop()
Login Page Code
01 02 03 04 05 06 07 08 09 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 | # Required Module-1 :- pip install tk # Required Module-2 :- pip install mysql-connector-python from tkinter import * from tkinter import messagebox as msg import mysql.connector root = Tk() root.title( "LOGIN FORM" ) root.geometry( "620x400+300+130" ) root.config(bg = "#289589" ) db = mysql.connector.connect( host = "localhost" , user = "root" , password = " Enter your password" , database = "register" ) cur = db.cursor() def verify_data(): sql = f "Select Email, Password from students" cur.execute(sql) login = cur.fetchall() email = user.get() Password = pswrd.get() check = (email, Password) if check in login: msg.showinfo( "Login" , "You Logged in Successfully." ) else : msg.showerror( "Error" , "Please Provide Right Credentials." ) Label(text = "LOGIN FORM" , font = ( "None 35 bold underline" ), bg = "#289589" ).place(x = 160 , y = 0 ) Label(text = "Email:" , font = ( "None 25 bold" ), bg = "#289589" ).place(x = 60 , y = 100 ) user = StringVar() Entry(root, textvariable = user, font = ( "None 20 bold" ), width = 24 ).place(x = 230 , y = 105 ) Label(text = "Password:" , font = ( "None 25 bold" ), bg = "#289589" ).place(x = 30 , y = 200 ) pswrd = StringVar() Entry(root, textvariable = pswrd, font = ( "None 20 bold" ), width = 24 ).place(x = 230 , y = 205 ) B = Button(root, text = "Login" , font = ( "None 25 bold" ), bg = "#268946" , activebackground = "#268946" , relief = RAISED, bd = 5 , command = verify_data) B.place(x = 250 , y = 300 ) root.mainloop() |
# Required Module-1 :- pip install tk
# Required Module-2 :- pip install mysql-connector-python
from tkinter import *
from tkinter import messagebox as msg
import mysql.connector
root = Tk()
root.title("LOGIN FORM")
root.geometry("620x400+300+130")
root.config(bg = "#289589")
db = mysql.connector.connect(
host="localhost",
user="root",
password="Enter your password",
database="register")
cur = db.cursor()
def verify_data():
sql = f"Select Email, Password from students"
cur.execute(sql)
login = cur.fetchall()
email = user.get()
Password = pswrd.get()
check = (email, Password)
if check in login:
msg.showinfo("Login", "You Logged in Successfully.")
else:
msg.showerror("Error", "Please Provide Right Credentials.")
Label(text="LOGIN FORM", font=("None 35 bold underline"), bg = "#289589").place(x = 160, y = 0)
Label(text="Email:", font=("None 25 bold"), bg = "#289589").place(x = 60, y = 100)
user = StringVar()
Entry(root, textvariable=user, font=("None 20 bold"), width=24).place(x = 230, y = 105)
Label(text="Password:", font=("None 25 bold"), bg = "#289589").place(x = 30, y = 200)
pswrd = StringVar()
Entry(root, textvariable=pswrd, font=("None 20 bold"), width=24).place(x = 230, y = 205)
B = Button(root, text="Login", font=("None 25 bold"), bg = "#268946", activebackground="#268946", relief=RAISED, bd = 5, command=verify_data)
B.place(x = 250, y = 300)
root.mainloop()
0 Comments