connection.py
import mysql.connector
import sys
def Connect():
conn=None
try:
conn=mysql.connector.connect(
host='localhost',
username='root',
password='',
database='taxi_booking_system'
)
except:
print("Error", sys.exc_info())
finally:
return conn
backend.py
import sys
from dbms.connection import Connect
def select_all720():
conn=None
sql="""SELECT * FROM booking"""
Bookresult=None
try:
conn=Connect()
cursor=conn.cursor()
cursor.execute(sql)
Bookresult=cursor.fetchall()
cursor.close()
conn.close()
except:
print("Error", sys.exc_info())
finally:
del sql, conn
return Bookresult
gui.py
from tkinter import *
from tkinter import ttk
from dbms.booking_backend import select_all
from test.test2 import select_all720
app=Tk()
app.geometry("500x400")
app.title("Hancie e-Learning Studio")
treeView=ttk.Treeview(app)
treeView.pack()
treeView['columns']=('id', 'pickupaddress','date')
treeView.column('#0', width=0, stretch=0)
treeView.column('id', width=100, anchor=CENTER)
treeView.column('pickupaddress', width=200, anchor=CENTER)
treeView.column('date', width=100, anchor=CENTER)
treeView.heading('#0', text='', anchor=CENTER)
treeView.heading('id', text="ID", anchor=CENTER)
treeView.heading('pickupaddress', text="Pickup address", anchor=CENTER)
treeView.heading('date', text="Date", anchor=CENTER)
def bookingtable():
Bookresult = select_all720()
i=0
for ro in Bookresult:
treeView.insert(parent='', index='end', values=(ro[0], ro[1], ro[2]))
bookingtable()
app.mainloop()
Output