Billing System using tkinter
Hello World
Here i am using python tkinter .
from tkinter import *
import math,random
from tkinter import messagebox
import os
class Bill_App:
def __init__(self,root):
self.root=root
self.root.geometry("1350x700+0+0")
self.root.title('Billing System')
bg_color ='#FFA32C'
title = Label(self.root, text="Billing System",relief=GROOVE,bg=bg_color,bd=12,fg='white',font=('times new roman',30,'bold'),pady=2).pack(fill=X)
#=====================variable==================================================
#======================cosmetics============================
self.soap=IntVar()
self.face_cream=IntVar()
self.face_wash=IntVar()
self.spray=IntVar()
self.gel=IntVar()
self.lotion=IntVar()
#======================grocery==============================
self.dal=IntVar()
self.rice=IntVar()
self.sugar=IntVar()
self.salt=IntVar()
self.tea=IntVar()
self.oil=IntVar()
#======================cold-drinks==========================
self.coca_cola=IntVar()
self.thumbs_up=IntVar()
self.fruti=IntVar()
self.limca=IntVar()
self.sprite=IntVar()
self.maza=IntVar()
#======================total product price & tax==============================
self.cosmetic_price=StringVar()
self.grocery_price=StringVar()
self.cold_drink_price=StringVar()
self.cosmetic_tax=StringVar()
self.grocery_tax=StringVar()
self.cold_drink_tax=StringVar()
#======================customer==============================
self.c_name=StringVar()
self.c_phone=StringVar()
self.bill_no=StringVar()
xy=random.randint(1000,9999)
self.bill_no.set(str(xy))
self.search_bill=StringVar()
#========================*_*==========================================
#===============customer detail frame=================
F1 = LabelFrame(self.root,bd=10,relief=GROOVE,text='Customer Details',font=('times new roman',15,'bold'),fg='yellow',bg=bg_color)
F1.place(x=0, y=80,relwidth=1)
cname_label=Label(F1,text="Customer Name",bg=bg_color,fg='white',font=('times new roman',18,'bold')).grid(row=0,column=0,padx=20,pady=5)
cname_txt = Entry(F1,width=15,textvariable=self.c_name,font="arial 15",bd=5,relief=SUNKEN).grid(row=0,column=1,pady=5,padx=10)
cphone_label=Label(F1,text="Phone No.",bg=bg_color,fg='white',font=('times new roman',18,'bold')).grid(row=0,column=2,padx=20,pady=5)
cphone_txt = Entry(F1,width=15,textvariable=self.c_phone,font="arial 15",bd=5,relief=SUNKEN).grid(row=0,column=3,pady=5,padx=10)
cbill_label=Label(F1,text=" Bill Number",bg=bg_color,fg='white',font=('times new roman',18,'bold')).grid(row=0,column=4,padx=20,pady=5)
cbill_txt = Entry(F1,width=15,textvariable=self.search_bill,font="arial 15",bd=5,relief=SUNKEN).grid(row=0,column=5,pady=5,padx=10)
bill_btn=Button(F1,text='search',command=self.find_bill,width=10,bd=5,font='arial 12 bold').grid(row=0,column=6,pady=10,padx=10)
#=====================cosmetic frame=================
F2=LabelFrame(self.root,bd=10,relief=GROOVE,text='Cosmetics',font=('times new roman',15,'bold'),fg='yellow',bg=bg_color)
F2.place(x=5, y=180,width=325,height=380)
bath_label=Label(F2,text='bath soap',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=0,column=0,padx=10,pady=10,sticky='w')
bath_txt=Entry(F2,width=10,textvariable=self.soap,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=0,column=1,padx=10,pady=10)
facecream_label=Label(F2,text='Face Cream',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=1,column=0,padx=10,pady=10,sticky='w')
facecream_txt=Entry(F2,textvariable=self.face_cream,width=10,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=1,column=1,padx=10,pady=10)
face_w_label=Label(F2,text='Face Wash',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=2,column=0,padx=10,pady=10,sticky='w')
face_w_txt=Entry(F2,width=10,textvariable=self.face_wash,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=2,column=1,padx=10,pady=10)
Hair_s_label=Label(F2,text='Hair Spray',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=3,column=0,padx=10,pady=10,sticky='w')
Hair_s_txt=Entry(F2,width=10,textvariable=self.spray,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=3,column=1,padx=10,pady=10)
body_lotion_label=Label(F2,text='Body Lotion',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=4,column=0,padx=10,pady=10,sticky='w')
body_lotion_txt=Entry(F2,width=10,textvariable=self.lotion,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=4,column=1,padx=10,pady=10)
hair_gel_label=Label(F2,text='Hair Gel',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=5,column=0,padx=10,pady=10,sticky='w')
hair_gel_txt=Entry(F2,width=10,textvariable=self.gel,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=5,column=1,padx=10,pady=10)
#=====================Grocery frame=================
F3=LabelFrame(self.root,bd=10,relief=GROOVE,text='Grocery',font=('times new roman',15,'bold'),fg='yellow',bg=bg_color)
F3.place(x=340, y=180,width=325,height=380)
g1_label=Label(F3,text='Dal',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=0,column=0,padx=10,pady=10,sticky='w')
g1_txt=Entry(F3,width=10,textvariable=self.dal,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=0,column=1,padx=10,pady=10)
g2_label=Label(F3,text='Rice',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=1,column=0,padx=10,pady=10,sticky='w')
g2_txt=Entry(F3,width=10,textvariable=self.rice,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=1,column=1,padx=10,pady=10)
g3_label=Label(F3,text='Sugar',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=2,column=0,padx=10,pady=10,sticky='w')
g3_txt=Entry(F3,width=10,textvariable=self.salt,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=2,column=1,padx=10,pady=10)
g4_label=Label(F3,text='Salt',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=3,column=0,padx=10,pady=10,sticky='w')
g4_txt=Entry(F3,width=10,textvariable=self.sugar,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=3,column=1,padx=10,pady=10)
g5_label=Label(F3,text='Tea',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=4,column=0,padx=10,pady=10,sticky='w')
g5_txt=Entry(F3,width=10,textvariable=self.tea,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=4,column=1,padx=10,pady=10)
g6_label=Label(F3,text='Oil',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=5,column=0,padx=10,pady=10,sticky='w')
g6_txt=Entry(F3,width=10,textvariable=self.oil,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=5,column=1,padx=10,pady=10)
#=====================cold-drink frame=================
F4=LabelFrame(self.root,bd=10,relief=GROOVE,text='Cold-Drinks',font=('times new roman',15,'bold'),fg='yellow',bg=bg_color)
F4.place(x=670, y=180,width=325,height=380)
c1_label=Label(F4,text='Coca Cola',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=0,column=0,padx=10,pady=10,sticky='w')
c1_txt=Entry(F4,width=10,textvariable=self.coca_cola,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=0,column=1,padx=10,pady=10)
c2_label=Label(F4,text='Thumbs up',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=1,column=0,padx=10,pady=10,sticky='w')
c2_txt=Entry(F4,width=10,textvariable=self.thumbs_up,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=1,column=1,padx=10,pady=10)
c3_label=Label(F4,text='Fruti',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=2,column=0,padx=10,pady=10,sticky='w')
c3_txt=Entry(F4,width=10,textvariable=self.fruti,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=2,column=1,padx=10,pady=10)
c4_label=Label(F4,text='Limca',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=3,column=0,padx=10,pady=10,sticky='w')
c4_txt=Entry(F4,width=10,textvariable=self.limca,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=3,column=1,padx=10,pady=10)
c5_label=Label(F4,text='Sprite',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=4,column=0,padx=10,pady=10,sticky='w')
c5_txt=Entry(F4,width=10,textvariable=self.sprite,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=4,column=1,padx=10,pady=10)
c6_label=Label(F4,text='Maza',font=('times new roman',16,'bold'),bg=bg_color,fg='blue').grid(row=5,column=0,padx=10,pady=10,sticky='w')
c6_txt=Entry(F4,width=10,textvariable=self.maza,font=('times new roman',16,'bold'),bd=5,relief=SUNKEN).grid(row=5,column=1,padx=10,pady=10)
#====================Bill area================================
F5=Frame(self.root,bd=10,relief=GROOVE)
F5.place(x=1010, y=180,width=340,height=380)
bill_title=Label(F5,text='Bill Area',font=('times new roman', 15 ,'bold'),bg=bg_color,fg='white',bd=7,relief=GROOVE).pack(fill=X)
scroll_y=Scrollbar(F5,orient=VERTICAL)
self.txtarea=Text(F5,yscrollcommand=scroll_y.set)
scroll_y.pack(side=RIGHT,fill=Y)
scroll_y.config(command=self.txtarea.yview)
self.txtarea.pack(fill=BOTH,expand=1)
#====================button frame===========================
F6=LabelFrame(self.root,bd=10,relief=GROOVE,text='Bill Menu',font=('times new roman',15,'bold'),fg='yellow',bg=bg_color)
F6.place(x=0, y=560,relwidth=1,height=140)
m1_label=Label(F6, text='Total Cosmetic Price',bg=bg_color,fg='white',font=('times new roman',14,'bold')).grid(row=0,column=0,padx=20,pady=1,sticky='w')
m1_txt=Entry(F6,width=18,textvariable=self.cosmetic_price,font='arial 10 bold',bd=7,relief=SUNKEN).grid(row=0,column=1,padx=10,pady=1)
m2_label=Label(F6, text='Total Grocery Price',bg=bg_color,fg='white',font=('times new roman',14,'bold')).grid(row=1,column=0,padx=20,pady=1,sticky='w')
m2_txt=Entry(F6,width=18,textvariable=self.grocery_price,font='arial 10 bold',bd=7,relief=SUNKEN).grid(row=1,column=1,padx=10,pady=1)
m3_label=Label(F6, text='Total Cold Drinks Price',bg=bg_color,fg='white',font=('times new roman',14,'bold')).grid(row=2,column=0,padx=20,pady=1,sticky='w')
m3_txt=Entry(F6,width=18,textvariable=self.cold_drink_price,font='arial 10 bold',bd=7,relief=SUNKEN).grid(row=2,column=1,padx=10,pady=1)
c1_label=Label(F6, text='Cosmetic Tax',bg=bg_color,fg='white',font=('times new roman',14,'bold')).grid(row=0,column=2,padx=20,pady=1,sticky='w')
c1_txt=Entry(F6,width=18,textvariable=self.cosmetic_tax,font='arial 10 bold',bd=7,relief=SUNKEN).grid(row=0,column=3,padx=10,pady=1)
c2_label=Label(F6, text='Grocery Tax',bg=bg_color,fg='white',font=('times new roman',14,'bold')).grid(row=1,column=2,padx=20,pady=1,sticky='w')
c2_txt=Entry(F6,width=18,textvariable=self.grocery_tax,font='arial 10 bold',bd=7,relief=SUNKEN).grid(row=1,column=3,padx=10,pady=1)
c3_label=Label(F6, text='Cold Drinks Tax',bg=bg_color,fg='white',font=('times new roman',14,'bold')).grid(row=2,column=2,padx=20,pady=1,sticky='w')
c3_txt=Entry(F6,width=18,textvariable=self.cold_drink_tax,font='arial 10 bold',bd=7,relief=SUNKEN).grid(row=2,column=3,padx=10,pady=1)
btn_f=Frame(F6,bd=7,relief=GROOVE)
btn_f.place(x=750,width=580,height=105)
total_btn=Button(btn_f,command=self.total,text='Total',bg='gray',bd=2,fg='white',font='arial 14 bold',width=10,pady=15).grid(row=0,column=0,padx=5,pady=5)
gbill_btn=Button(btn_f,text='Genrate Bill',command=self.bill_area,bg='gray',bd=2,fg='white',font='arial 14 bold',width=10,pady=15).grid(row=0,column=1,padx=5,pady=5)
clear_btn=Button(btn_f,text='Clear',command=self.clear_data,bg='gray',bd=2,fg='white',font='arial 14 bold',width=10,pady=15).grid(row=0,column=2,padx=5,pady=5)
exit_btn=Button(btn_f,text='Exit',command=self.exit_app,bg='gray',bd=2,fg='white',font='arial 14 bold',width=10,pady=15).grid(row=0,column=3,padx=5,pady=5)
self.welcome_bill()
#=========================for price=========================
def total(self):
self.c_s_p = self.soap.get()*40
self.c_fc_p = self.face_cream.get()*120
self.c_fw_p = self.face_wash.get()*60
self.c_hs_p = self.spray.get()*150
self.c_hg_p = self.gel.get()*140
self.c_bl_p = self.lotion.get()*180
self.total_cosmetic_price=float(
self.c_s_p+
self.c_fc_p+
self.c_fw_p+
self.c_hs_p+
self.c_hg_p+
self.c_bl_p
)
self.cosmetic_price.set("Rs." +str(self.total_cosmetic_price))
self.c_tax=round((self.total_cosmetic_price*0.05),2)
self.cosmetic_tax.set("Rs." +str(self.c_tax))
self.g_d_p = self.dal.get()*80
self.g_r_p = self.rice.get()*180
self.g_s_p = self.sugar.get()*45
self.g_sa_p= self.salt.get()*60
self.g_t_p = self.tea.get()*60
self.g_o_p = self.oil.get()*200
self.total_grocery_price=float(
self.g_d_p+
self.g_r_p+
self.g_s_p+
self.g_sa_p+
self.g_t_p+
self.g_o_p
)
self.grocery_price.set("Rs." +str(self.total_grocery_price))
self.g_tax=round((self.total_grocery_price*0.1),2)
self.grocery_tax.set("Rs." +str(self.g_tax))
self.co_cc_p = self.coca_cola.get()*60
self.co_tu_p = self.thumbs_up.get()*60
self.co_f_p = self.fruti.get()*55
self.co_l_p = self.limca.get()*55
self.co_s_p = self.sprite.get()*60
self.co_m_p = self.maza.get()*40
self.total_drinks_price=float(
self.co_cc_p+
self.co_tu_p+
self.co_f_p+
self.co_l_p+
self.co_s_p+
self.co_m_p
)
self.cold_drink_price.set("Rs." +str(self.total_drinks_price))
self.d_tax=round((self.total_drinks_price*0.05),2)
self.cold_drink_tax.set("Rs." +str(self.d_tax))
self.total_bill=float(self.total_cosmetic_price+
self.total_grocery_price+
self.total_drinks_price+
self.c_tax+
self.g_tax+
self.d_tax
)
def welcome_bill(self):
self.txtarea.delete('1.0',END)
self.txtarea.insert(END,'\twelcome System Owner\n')
self.txtarea.insert(END,f'\nBill Number :{self.bill_no.get()}')
self.txtarea.insert(END,f'\nCustomer Name :{self.c_name.get()}')
self.txtarea.insert(END,f'\nPhone Number :{self.c_phone.get()}')
self.txtarea.insert(END,f'\n=====================================')
self.txtarea.insert(END,f'\n Products\t\tQty\t\tPrice')
self.txtarea.insert(END,f'\n=====================================')
def bill_area(self):
if self.c_name.get()=='' or self.c_phone.get()=='':
messagebox.showerror('Error','Customer details are required!')
elif self.cosmetic_price.get()=='Rs.0.0' and self.grocery_price.get()=='Rs.0.0' and self.cold_drink_price.get()=='Rs.0.0':
messagebox.showerror('Error','No product puschased')
else:
self.welcome_bill()
#======cosmetics=============================
if self.soap.get()!=0:
self.txtarea.insert(END,f'\n Bath Soap\t\t{self.soap.get()}\t\t{self.c_s_p}')
if self.face_cream.get()!=0:
self.txtarea.insert(END,f'\n Face Cream\t\t{self.face_cream.get()}\t\t{self.c_fc_p}')
if self.face_wash.get()!=0:
self.txtarea.insert(END,f'\n Face Wash\t\t{self.face_wash.get()}\t\t{self.c_fw_p}')
if self.spray.get()!=0:
self.txtarea.insert(END,f'\n Hair spray\t\t{self.spray.get()}\t\t{self.c_hs_p}')
if self.lotion.get()!=0:
self.txtarea.insert(END,f'\n Body Lotion\t\t{self.lotion.get()}\t\t{self.c_bl_p}')
if self.gel.get()!=0:
self.txtarea.insert(END,f'\n Hair gel\t\t{self.gel.get()}\t\t{self.c_hg_p}')
#======grocery=============================
if self.dal.get()!=0:
self.txtarea.insert(END,f'\n dal\t\t{self.dal.get()}\t\t{self.g_d_p}')
if self.rice.get()!=0:
self.txtarea.insert(END,f'\n rice\t\t{self.rice.get()}\t\t{self.g_r_p}')
if self.sugar.get()!=0:
self.txtarea.insert(END,f'\n sugar\t\t{self.sugar.get()}\t\t{self.g_s_p}')
if self.salt.get()!=0:
self.txtarea.insert(END,f'\n salt\t\t{self.salt.get()}\t\t{self.g_sa_p}')
if self.tea.get()!=0:
self.txtarea.insert(END,f'\n tea\t\t{self.tea.get()}\t\t{self.g_t_p}')
if self.oil.get()!=0:
self.txtarea.insert(END,f'\n oil\t\t{self.oil.get()}\t\t{self.g_o_p}')
#======cold-drinks=============================
if self.coca_cola.get()!=0:
self.txtarea.insert(END,f'\n coca cola\t\t{self.coca_cola.get()}\t\t{self.co_cc_p}')
if self.thumbs_up.get()!=0:
self.txtarea.insert(END,f'\n thumbs up\t\t{self.thumbs_up.get()}\t\t{self.co_tu_p}')
if self.fruti.get()!=0:
self.txtarea.insert(END,f'\n fruti\t\t{self.fruti.get()}\t\t{self.co_f_p}')
if self.limca.get()!=0:
self.txtarea.insert(END,f'\n limca\t\t{self.limca.get()}\t\t{self.co_l_p}')
if self.sprite.get()!=0:
self.txtarea.insert(END,f'\n sprite\t\t{self.sprite.get()}\t\t{self.co_s_p}')
if self.maza.get()!=0:
self.txtarea.insert(END,f'\n maza\t\t{self.maza.get()}\t\t{self.co_m_p}')
self.txtarea.insert(END,f'\n-------------------------------------')
if self.cosmetic_tax.get()!="Rs.0.0":
self.txtarea.insert(END,f'\n Cosmetic Tax :\t\t\t{self.cosmetic_tax.get()}')
if self.grocery_tax.get()!="Rs.0.0":
self.txtarea.insert(END,f'\n Grocery Tax :\t\t\t{self.grocery_tax.get()}')
if self.cold_drink_tax.get()!="Rs.0.0":
self.txtarea.insert(END,f'\n Cold Drink Tax :\t\t\t{self.cold_drink_tax.get()}')
self.txtarea.insert(END,f'\n Total Bill : \t\t\tRs.{self.total_bill}')
self.txtarea.insert(END,f'\n-------------------------------------')
self.save_bill()
def save_bill(self):
op=messagebox.askyesno("Save Bill","Do you want to save the bill?")
if op>0:
self.bill_data=self.txtarea.get('1.0',END)
f1=open("web design/bills/" + str(self.bill_no.get()) + ".txt",'w')
f1.write(self.bill_data)
f1.close()
messagebox.showinfo('Saved',f'Bill no. {self.bill_no.get()} saved Successfully')
else:
return
def find_bill(self):
present='no'
for i in os.listdir('web design/bills/'):
if i.split('.')[0]==self.search_bill.get():
f1=open(f"web design/bills/{i}",'r')
self.txtarea.delete('1.0',END)
for d in f1:
self.txtarea.insert(END,d)
f1.close()
present='yes'
if present=='no':
messagebox.showerror('Error','Invalid Bill No.')
def clear_data(self):
cd=messagebox.askyesno('Clear','Do you want to clear data?')
if cd>0:
#======================cosmetics==============================
self.soap.set(0)
self.face_cream.set(0)
self.face_wash.set(0)
self.spray.set(0)
self.gel.set(0)
self.lotion.set(0)
#======================grocery==============================
self.dal.set(0)
self.rice.set(0)
self.sugar.set(0)
self.salt.set(0)
self.tea.set(0)
self.oil.set(0)
#======================cold-drinks==============================
self.coca_cola.set(0)
self.thumbs_up.set(0)
self.fruti.set(0)
self.limca.set(0)
self.sprite.set(0)
self.maza.set(0)
#======================total product price & tax==============================
self.cosmetic_price.set('')
self.grocery_price.set('')
self.cold_drink_price.set('')
self.cosmetic_tax.set('')
self.grocery_tax.set('')
self.cold_drink_tax.set('')
#======================customer==============================
self.c_name.set('')
self.c_phone.set('')
self.bill_no.set('')
xy=random.randint(1000,9999)
self.bill_no.set(str(xy))
self.search_bill.set('')
self.welcome_bill()
def exit_app(self):
ex=messagebox.askyesno('Exit','Do you want to exit?')
if ex>0:
self.root.destroy()
root = Tk()
obj = Bill_App(root)
root.mainloop()
Comments
Post a Comment