from tkinter import *
from tkinter import ttk
from dbms.billing_backend import billing_history12
class Hancie():
def __init__(self, main):
self.main=main
self.main.title("Hancie e-Learning Studio")
self.main.resizable(0, 0)
frame_width = 1050
frame_height = 500
screen_width = self.main.winfo_screenwidth()
screen_height = self.main.winfo_screenheight()
x_cordinate = int((screen_width / 2) - (frame_width / 2))
y_cordinate = int((screen_height / 2) - (frame_height / 2))
self.main.geometry('{}x{}+{}+{}'.format(frame_width, frame_height, x_cordinate+50, y_cordinate+50))
treeView=ttk.Treeview(self.main)
treeView.pack(side=BOTTOM, fill=BOTH, expand=True)
treeView['columns']=('bookingid', 'name','km','unit','total')
treeView.column('#0', width=0, stretch=0)
treeView.column('bookingid', width=100, anchor=CENTER)
treeView.column('name', width=200, anchor=CENTER)
treeView.column('km', width=100, anchor=CENTER)
treeView.column('unit', width=100, anchor=CENTER)
treeView.column('total', width=150, anchor=CENTER)
treeView.heading('#0', text='', anchor=CENTER)
treeView.heading('bookingid',text='ID', anchor=CENTER)
treeView.heading('name', text='Name', anchor=CENTER)
treeView.heading('km', text='KM', anchor=CENTER)
treeView.heading('unit', text='Unit', anchor=CENTER)
treeView.heading('total', text='Total', anchor=CENTER)
def billingtable():
historyResult=billing_history12()
for ro in historyResult:
treeView.insert(parent='', index='end', values=(ro[0],ro[1],ro[6],ro[7],ro[8]))
billingtable()
def getaverage(item=""):
val = 0
for row in treeView.get_children(item):
# print(trv.item(row)["values"][3])# print price
val = val + treeView.item(row)["values"][4]
average = val / len(treeView.get_children())
treeView.insert(parent='', index='end', values=('','','','',"Average: {}".format(average)))
getaverage()
if __name__=='__main__':
main=Tk()
Hancie(main)
main.mainloop()
Output