
def show_items(cat): # Populating the Combobox
global my_menu,my_menu2
my_menu.clear() # remove all items
cb1.set('')
e1.delete(0,END)
r_set=my_conn.execute("SELECT * FROM plus2_products WHERE \
available=1 and p_cat="+str(cat))
for item in r_set:
my_menu.update({item[0]:item[1]})
my_menu2.update({item[1]:[item[0],item[1],item[3]]})
options=list(my_menu.values())
cb1.config(values=options)
b1=tk.Button(frame_m_left,text='Add',font=font2,
command=lambda:my_add())
b1.grid(row=0,column=2,padx=10)
show_items(1)
def my_add(): #adding item to bill
try:
p_id=my_menu2[sel.get()][0]
p_name=sel.get()
price=e1.get()
quantity=my_menu2[sel.get()][2]
except:
return None
if(int(quantity)>0 and len(p_name)>0 and p_id>0):
sub_total=round(float(price)*int(quantity),2)
trv.insert("",'end',text=p_id,values=[p_name,price,quantity,sub_total])
my_sum() # re-calculate the total
cb1.set('') # reset the combobox
e1.delete(0,END)# reset the entry widget
def my_sum(): # Calculate total and tax part
total=0
for line in trv.get_children(): # Loop through all items
total=total+float(trv.item(line)['values'][3])
tax=round(0.1*total,2) # change the tax rate here
final=round(total+tax,2) # final price
lr2.config(text=str(total)) # show it at Label
lr22.config(text=str(tax)) # show it at Label
lr32.config(text=str(final))# show it at Label
def my_reset():
for item in trv.get_children(): # loop all child items
trv.delete(item) # delete them
my_sum() # call the re-calculate and update the labels text
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.