'Calculating issues in final project

I am really struggling with my code that deals with electricity billing in python. The main issue here is that I don't know where to add my calculations to be appearing in the billing area. I have to make the billing area look like a receipt so I need to show the total, subtotal etc.

The calculations are that if the number of kwh is bigger than 0 but less than a 1000, you pay the regular price of electricity which is 0.098 cents by kWh. But if the number of kilowatts is bigger than a 1000, you pay an additional 0.115 cents by each extra kilowatts. It should look like this :

if (k>0 and k<=1000):
price= 0.098* (number of kWh)= k

elif (k>1000):
z= k-1000
total= z*0.115+price

Can somebody please create a tkinter python dealing with the electricity billing as there's not much resources I can find online. I would be very happy if the code runs without hard inputs since I am a beginner in python. Thank you very much!

    from tkinter import *
from tkinter import messagebox
import random
root=Tk()
root.title("bill slip")
root.geometry('1280x720')
bg_color='#4D0039'

#======================variable=================
CustomerName=StringVar()
CustomerComp=StringVar()
Adress=StringVar()
K=IntVar()
bill_no=StringVar()
x=random.randint(1000,9999)
bill_no.set(str(x))

global l
l=[]
prix= 0.098*K
#=========================Functions================================

z= K-1000
total= z*0.115+prix
t= total*0.13
prix2= t+total
prix= 0.098*K
totaltaxe= prix*0.13
tax= totaltaxe+K
def gbill():
   if CustomerName.get() == "" or CustomerComp.get() == "":
       messagebox.showerror("Error", "Customer detail are must")
   else:
       textAreaText = textarea.get(10.0,(10.0+float(len(l))))
       welcome()
       textarea.insert(END, textAreaText)
       textarea.insert(END, f"\n======================================")
       textarea.insert(END, f"\nTotal Paybill Amount :\t\t      {sum(l)}")
       textarea.insert(END, f"\n\n======================================")
       textarea.insert(END, f"\n\n- Tarif regulier...........{prix}$")
       textarea.insert(END, f"\n\n- Tarif suplementaire..................{total}$")
       textarea.insert(END, f"\n\n- Sous-total..................{totaltaxe or prix2}$")
       textarea.insert(END, f"\n\n- TVH..................{t or tax}$")

z= K-1000
total= z*0.115+prix
t= total*0.13
prix2= t+total
prix= 0.098*K
totaltaxe= prix*0.13
tax= totaltaxe+K
prix= 0.098*K



def clear():
   CustomerName.set('')
   CustomerComp.set('')
   Adress.set('')
   K.set(0)
   welcome()
def exit():
   op = messagebox.askyesno("Exit", "Do you really want to exit?")
   if op > 0:
       root.destroy()

def welcome():
   textarea.delete(1.0,END)
   textarea.insert(END,"\t  Bill :")
   textarea.insert(END,f"\n\nBill Number:\t\t{bill_no.get()}")
   textarea.insert(END,f"\nCustomer Name:\t\t{CustomerName.get()}")
   textarea.insert(END,f"\nCounter number:\t\t{CustomerComp.get()}")
   textarea.insert(END, f"\n"f"-Normal bill = 1000 kWh/0.098c\t\t")
   textarea.insert(END, f"\n"f"-Additional bill = +0.15c/kWh for each kWh extra\t\t")

   prix = 0.098 * K
   z = K - 1000
   total = z * 0.115 + prix
   t = total * 0.13
   prix2 = t + total

   if (K>0 and K<=1000):
       prix= 0.098*K
       totaltaxe= prix*0.13
       tax= totaltaxe+K
   elif (K>1000):
       z= K-1000
       total= z*0.115+prix
       t= total*0.13
       prix2= t+total



   textarea.insert(END,f"\n\n======================================")
   textarea.insert(END,"\nProduct\t\tQTY\t\tPrice")
   textarea.insert(END,f"\n======================================\n")
   textarea.configure(font='arial 15 bold')



title=Label(root,pady=2,text="Billing Software",bd=12,bg=bg_color,fg='white',font=('times new roman', 25 ,'bold'),relief=GROOVE,justify=CENTER)
title.pack(fill=X)

#=================Product Frames=================
F1=LabelFrame(root,bd=10,relief=GROOVE,text='Customer Details',font=('times new romon',15,'bold'),fg='gold',bg=bg_color)
F1.place(x=0,y=80,relwidth=1)

cname_lbl=Label(F1,text='Customer Name',font=('times new romon',18,'bold'),bg=bg_color,fg='white').grid(row=0,column=0,padx=20,pady=5)
cname_txt=Entry(F1,width=15,textvariable=CustomerName,font='arial 15 bold',relief=SUNKEN,bd=7).grid(row=0,column=1,padx=10,pady=5)

cphone_lbl=Label(F1,text='Customer Counter number',font=('times new romon',18,'bold'),bg=bg_color,fg='white').grid(row=0,column=2,padx=20,pady=5)
cphone_txt=Entry(F1,width=15,font='arial 15 bold',textvariable=CustomerComp,relief=SUNKEN,bd=7).grid(row=0,column=3,padx=10,pady=5)

F2 = LabelFrame(root, text='Product Details', font=('times new romon', 18, 'bold'), fg='gold',bg=bg_color)
F2.place(x=20, y=180,width=630,height=500)

itm= Label(F2, text='Customer Adress', font=('times new romon',18, 'bold'), bg=bg_color, fg='lightgreen').grid(
row=0, column=0, padx=30, pady=20)
itm_txt = Entry(F2, width=20,textvariable=CustomerComp, font='arial 15 bold', relief=SUNKEN, bd=7).grid(row=0, column=1, padx=10,pady=20)

rate= Label(F2, text='Amount of Kilowatts :', font=('times new romon',18, 'bold'), bg=bg_color, fg='lightgreen').grid(
row=1, column=0, padx=30, pady=20)
rate_txt = Entry(F2, width=20,textvariable=K, font='arial 15 bold', relief=SUNKEN, bd=7).grid(row=1, column=1, padx=10,pady=20)



#========================Bill area================
F3=Frame(root,relief=GROOVE,bd=10)
F3.place(x=700,y=180,width=500,height=500)

bill_title=Label(F3,text='Bill Area',font='arial 15 bold',bd=7,relief=GROOVE).pack(fill=X)
scrol_y=Scrollbar(F3,orient=VERTICAL)
textarea=Text(F3,yscrollcommand=scrol_y)
scrol_y.pack(side=RIGHT,fill=Y)
scrol_y.config(command=textarea.yview)
textarea.pack()
welcome()
#=========================Buttons======================

btn2=Button(F2,text='Generate Bill',font='arial 15 bold',command=gbill,padx=5,pady=10,bg='lime',width=15)
btn2.grid(row=3,column=1,padx=10,pady=30)
btn3=Button(F2,text='Clear',font='arial 15 bold',padx=5,pady=10,command=clear,bg='lime',width=15)
btn3.grid(row=4,column=0,padx=10,pady=30)
btn4=Button(F2,text='Exit',font='arial 15 bold',padx=5,pady=10,command=exit,bg='lime',width=15)
btn4.grid(row=4,column=1,padx=10,pady=30)

root.mainloop()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source