connection.py
import mysql.connector
import sys
def Connect():
conn=None
try:
conn=mysql.connector.connect(
host='localhost',
username='root',
password='',
database='level4b'
)
except:
print("Error", sys.exc_info())
finally:
return conn
libs.py
class Libs():
def __init__(self, cid=0,
name=None, dob=None, email=None, password=None):
self.cid=cid
self.name=name
self.dob=dob
self.email=email
self.password=password
#Getter
def getCid(self):
return self.cid
def getName(self):
return self.name
def getDob(self):
return self.dob
def getEmail(self):
return self.email
def getPassword(self):
return self.password
#setter
def setCid(self, cid):
self.cid=cid
def setName(self, name):
self.name=name
def setDob(self, dob):
self.dob=dob
def setEmail(self, email):
self.email=email
def setPassword(self, password):
self.password=password
def __str__(self):
return ('{},{},{},{},{}'.format(self.cid,
self.name, self.dob, self.email, self.password))
backend.py
from Hancie.connection import Connect
import mysql.connector
import sys
def get_alldata():
conn=None
sql="""SELECT name FROM customers"""
Result=None
try:
conn=Connect()
cursor=conn.cursor()
cursor.execute(sql)
Result=cursor.fetchall()
cursor.close()
conn.close()
except:
print("Error", sys.exc_info())
finally:
del sql, conn
return Result
gui.py
from tkinter import *
from tkinter import ttk
from Hancie.backend import get_alldata
class Hancie():
def __init__(self, main):
self.main=main
self.main.title("Hancie e-Learning Studio")
self.main.geometry("500x400")
myfont=('Tahoma',16)
searchlbl = Label(self.main, text="Name:", font=myfont)
searchlbl.place(x=20, y=50)
Result = get_alldata()
comboxdata = [r for r, in Result]
nameCombo = ttk.Combobox(self.main,values=comboxdata, font=myfont)
nameCombo.place(x=120, y=50)
if __name__=='__main__':
main=Tk()
Hancie(main)
main.mainloop()
Output