import mysql.connector
import sys
def Connect():
conn=None
try:
conn=mysql.connector.Connect(
host='localhost',
username='root',
password='',
database='hancie'
)
except:
print('Error', sys.exc_info())
finally:
return conn
loginbackend.py
from backend.database import Connect
import sys
def login(id):
conn=None
sql="""SELECT * FROM test720 WHERE email=%s AND password=%s"""
values=(id.getEmail(), id.getPassword())
result=None
try:
conn=Connect()
cursor=conn.cursor()
cursor.execute(sql, values)
result=cursor.fetchone()
cursor.close()
conn.close()
except:
print('Error',sys.exc_info())
finally:
del values, sql, conn
return result
customerlibrary.py
class CustomerLibs():
def __init__(self, id=0, email=None, password=None):
self.id=id
self.email=email
self.password=password
def getId(self):
return self.id
def getEmail(self):
return self.email
def getPassword(self):
return self.password
def setId(self, id):
self.id=id
def setEmail(self, email):
self.email=email
def setPassword(self, password):
self.password=password
def __str__(self):
return ('{},{},{}'.format(self.id, self.email,self.password))
login.py
from tkinter import *
from tkinter import messagebox
from backend.loginbackend import login
from middleware.customerlibrary import CustomerLibs
class LoginGUI():
def __init__(self,root):
self.root=root
self.root.title('Hancie e-Learning Studio LOGIN')
self.root.geometry('500x400')
self.root.resizable(width=0, height=0)
frame=Frame(self.root, bg='green', height=60)
frame.pack(side=TOP, fill=BOTH)
titlelabel=Label(frame, text='LOGIN SYSTEM', font=('Times New Roman',16,'bold'))
titlelabel.place(relx=0.5, rely=0.5, anchor=CENTER)
emailabel=Label(self.root, text="Email:", font=('Times New Roman',14))
emailabel.place(x=60,y=100)
emailtext=Entry(self.root, font=('Times New Roman',14))
emailtext.place(x=200, y=100)
passwordlabel=Label(self.root, text="Password:", font=('Times New Roman',14))
passwordlabel.place(x=60, y=150)
passwordtext=Entry(self.root, font=('Times New Roman',14))
passwordtext.place(x=200, y=150)
def loginlogic():
customerdata=CustomerLibs(email=emailtext.get(), password=passwordtext.get())
result=login(customerdata)
if result!=None:
messagebox.showinfo("Hancie","Welcome {}".format(emailtext.get()))
else:
messagebox.showerror("Hancie","Incorrect email and password")
loginbtn=Button(self.root, text="Login",command=loginlogic, font=('Times New Roman',14))
loginbtn.place(x=200, y=200)
if __name__=='__main__':
root=Tk()
LoginGUI(root)
root.mainloop()
Output