0% found this document useful (0 votes)
8 views33 pages

Medical shop billing system code

Subhayu Biswas completed a Computer Science project titled 'Medical Billing System' under the guidance of Debjit Biswas for the academic year 2024-25. The project involves creating a billing software using Tkinter for the GUI and MySQL for database management, allowing users to input customer details and item quantities. Key features include random bill number generation, data insertion into the database, and a structured layout for medicines, health products, and hygiene items.

Uploaded by

biswassubhayu1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views33 pages

Medical shop billing system code

Subhayu Biswas completed a Computer Science project titled 'Medical Billing System' under the guidance of Debjit Biswas for the academic year 2024-25. The project involves creating a billing software using Tkinter for the GUI and MySQL for database management, allowing users to input customer details and item quantities. Key features include random bill number generation, data insertion into the database, and a structured layout for medicines, health products, and hygiene items.

Uploaded by

biswassubhayu1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 33

CERTIFICATE

This is to certify that Subhayu Biswas of class XII has


completed his Computer Science project titled Medical
Billing system under the guidance of Debjit Biswas for
the academic year 2024-25. The certified student has
been dedicated throughout his research and completed
his work before the given deadline without missing any
important details from the project.

Teacher’s signature Student’s signature

School Stamp Examiner Signature


MEDICAL BILLING SYSTEM:-
Explanation:

 Table Creation: The CREATE TABLE IF NOT EXISTS ensures that each table (items,
items_2, items_3) is only created if it doesn't already exist.
 Inserting Data: The executemany() function is used to insert multiple records for
each table in one go.
 Committing: The conn.commit() function saves the changes to the database.
 Closing the Cursor: cursor.close() is used to close the cursor.

from tkinter import *


import random
import mysql.connector as sql
conn=sql.connect(host="localhost",user="root",passwd="password123",data
base="medic")
cur=conn.cursor()
from tkinter import messagebox

class Bill_App:
def __init__(self,root):
self.root=root
self.root.geometry("1350x700+0+0")
self.root.configure(bg="#5B2C6F")
self.root.title("Billing Software")
title=Label(self.root,text="Marvel
Pharmacy",bd=12,relief=RIDGE,font=("Arial
Black",20),bg="#A569BD",fg="white").pack(fill=X)

#===================================variables==========================
=============================================================
self.para=IntVar()
self.pan_d=IntVar()
self.saridon=IntVar()
self.thyrox=IntVar()
self.ambizyme=IntVar()
self.ecosprin=IntVar()
self.broncophil=IntVar()
self.multivitamin=IntVar()
self.protein=IntVar()
self.ors=IntVar()
self.baby=IntVar()
self.endura=IntVar()
self.beta_g=IntVar()
self.vaseline=IntVar()
self.diaper=IntVar()
self.pad=IntVar()
self.beta_d=IntVar()
self.bandaid=IntVar()
self.cotton=IntVar()
self.sanitizer=IntVar()
self.wipes=IntVar()
self.total_med=StringVar()
self.total_hel=StringVar()
self.total_hyg=StringVar()
self.a=StringVar()
self.b=StringVar()
self.c=StringVar()
self.c_name=StringVar()
self.bill_no=StringVar()
x=random.randint(1000,9999)
self.bill_no.set(str(x))
self.phone=StringVar()
#==========================================customer details
label frame=================================================
details=LabelFrame(self.root,text="Customer
Details",font=("Arial
Black",12),bg="#A569BD",fg="white",relief=GROOVE,bd=10)
details.place(x=0,y=80,relwidth=1)
cust_name=Label(details,text="Customer Name",font=("Arial
Black",14),bg="#A569BD",fg="white").grid(row=0,column=0,padx=15)

cust_entry=Entry(details,borderwidth=4,width=30,textvariable=self.c_nam
e).grid(row=0,column=1,padx=8)

contact_name=Label(details,text="Contact No.",font=("Arial
Black",14),bg="#A569BD",fg="white").grid(row=0,column=2,padx=10)

contact_entry=Entry(details,borderwidth=4,width=30,textvariable=self.ph
one).grid(row=0,column=3,padx=8)

bill_name=Label(details,text="Bill.No.",font=("Arial
Black",14),bg="#A569BD",fg="white").grid(row=0,column=4,padx=10)

bill_entry=Entry(details,borderwidth=4,width=30,textvariable=self.bill_
no).grid(row=0,column=5,padx=8)
#=======================================Medicine label
frame=================================================================
medicine=LabelFrame(self.root,text="Medicine",font=("Arial
Black",12),bg="#E5B4F3",fg="#6C3483",relief=GROOVE,bd=10)
medicine.place(x=5,y=180,height=380,width=325)

item1=Label(medicine,text="Paracetamol(650mg)",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=0,column=0,pady=11)

item1_entry=Entry(medicine,borderwidth=2,width=15,textvariable=self.par
a).grid(row=0,column=1,padx=10)

item2=Label(medicine,text="Pan-D(1 strip)",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=1,column=0,pady=11)

item2_entry=Entry(medicine,borderwidth=2,width=15,textvariable=self.pan
_d).grid(row=1,column=1,padx=10)

item3=Label(medicine,text="Saridon(1 strip)",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=2,column=0,pady=11)

item3_entry=Entry(medicine,borderwidth=2,width=15,textvariable=self.sar
idon).grid(row=2,column=1,padx=10)

item4=Label(medicine,text="Thyrox(50 mg)",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=3,column=0,pady=11)

item4_entry=Entry(medicine,borderwidth=2,width=15,textvariable=self.thy
rox).grid(row=3,column=1,padx=10)

item5=Label(medicine,text="Ambizyme",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=4,column=0,pady=11)

item5_entry=Entry(medicine,borderwidth=2,width=15,textvariable=self.amb
izyme).grid(row=4,column=1,padx=10)

item6=Label(medicine,text="Ecosprin(75 mg)",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=5,column=0,pady=11)

item6_entry=Entry(medicine,borderwidth=2,width=15,textvariable=self.eco
sprin).grid(row=5,column=1,padx=10)

item7=Label(medicine,text="Broncophil(100 mg)",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=6,column=0,pady=11)

item7_entry=Entry(medicine,borderwidth=2,width=15,textvariable=self.bro
ncophil).grid(row=6,column=1,padx=10)

#===================================HEALTH=============================
========================================================
health=LabelFrame(self.root,text="Health",font=("Arial
Black",12),relief=GROOVE,bd=10,bg="#E5B4F3",fg="#6C3483")
health.place(x=340,y=180,height=380,width=325)

item8=Label(health,text="Multi-Vitamin",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=0,column=0,pady=11)

item8_entry=Entry(health,borderwidth=2,width=15,textvariable=self.multi
vitamin).grid(row=0,column=1,padx=10)

item9=Label(health,text="Protein-X",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=1,column=0,pady=11)

item9_entry=Entry(health,borderwidth=2,width=15,textvariable=self.prote
in).grid(row=1,column=1,padx=10)

item10=Label(health,text="Ors",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=2,column=0,pady=11)

item10_entry=Entry(health,borderwidth=2,width=15,textvariable=self.ors)
.grid(row=2,column=1,padx=10)

item11=Label(health,text="Himalaya-Powder(Baby)",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=3,column=0,pady=11)

item11_entry=Entry(health,borderwidth=2,width=15,textvariable=self.baby
).grid(row=3,column=1,padx=10)

item12=Label(health,text="Endura-Mass",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=4,column=0,pady=11)

item12_entry=Entry(health,borderwidth=2,width=15,textvariable=self.endu
ra).grid(row=4,column=1,padx=10)

item13=Label(health,text="Betadine-Gargle",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=5,column=0,pady=11)

item13_entry=Entry(health,borderwidth=2,width=15,textvariable=self.beta
_g).grid(row=5,column=1,padx=10)

item14=Label(health,text="Vaseline",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=6,column=0,pady=11)

item14_entry=Entry(health,borderwidth=2,width=15,textvariable=self.vase
line).grid(row=6,column=1,padx=10)

#========================================HYGIENE=======================
========================================================
hygiene=LabelFrame(self.root,text="Hygiene",font=("Arial
Black",12),relief=GROOVE,bd=10,bg="#E5B4F3",fg="#6C3483")
hygiene.place(x=677,y=180,height=380,width=325)

item15=Label(hygiene,text="Baby-Diapers",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=0,column=0,pady=11)

item15_entry=Entry(hygiene,borderwidth=2,width=15,textvariable=self.dia
per).grid(row=0,column=1,padx=10)

item16=Label(hygiene,text="Sanitary-Pad",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=1,column=0,pady=11)

item16_entry=Entry(hygiene,borderwidth=2,width=15,textvariable=self.pad
).grid(row=1,column=1,padx=10)

item17=Label(hygiene,text="Betadine",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=2,column=0,pady=11)

item17_entry=Entry(hygiene,borderwidth=2,width=15,textvariable=self.bet
a_d).grid(row=2,column=1,padx=10)

item18=Label(hygiene,text="Band-Aid",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=3,column=0,pady=11)

item18_entry=Entry(hygiene,borderwidth=2,width=15,textvariable=self.ban
daid).grid(row=3,column=1,padx=10)

item19=Label(hygiene,text="Cotton",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=4,column=0,pady=11)

item19_entry=Entry(hygiene,borderwidth=2,width=15,textvariable=self.cot
ton).grid(row=4,column=1,padx=10)

item20=Label(hygiene,text="Sanitizer",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=5,column=0,pady=11)

item20_entry=Entry(hygiene,borderwidth=2,width=15,textvariable=self.san
itizer).grid(row=5,column=1,padx=10)

item21=Label(hygiene,text="Baby-Wipes",font=("Arial
Black",11),bg="#E5B4F3",fg="#6C3483").grid(row=6,column=0,pady=11)

item21_entry=Entry(hygiene,borderwidth=2,width=15,textvariable=self.wip
es).grid(row=6,column=1,padx=10)

Key Components of the Code

1. Library Imports
 tkinter: Used for creating the graphical user interface (GUI).
 random: Generates a random bill number.
 mysql.connector: Used to connect to a MySQL database.
 messagebox: Displays messages like error notifications or success alerts.

2. Database Connection

python
Copy code
conn = sql.connect(host="localhost", user="root", passwd="password123",
database="medic")
cur = conn.cursor()

 Connects to a MySQL database named medic.


 A cursor object is created to execute SQL queries.

Creating tables on remote computer

 Table Creation: The CREATE TABLE IF NOT EXISTS ensures that each table (items,
items_2, items_3) is only created if it doesn't already exist.
 Inserting Data: The executemany() function is used to insert multiple records for
each table in one go.
 Committing: The conn.commit() function saves the changes to the database.
 Closing the Cursor: cursor.close() is used to close the cursor.

3. Class Initialization

python
Copy code
class Bill_App:
def __init__(self, root):
self.root = root
...

 The __init__ method initializes the application.


 root: The main Tkinter window passed to the class.
 Sets the window dimensions, title, and background color.

4. Variables for Items

python
Copy code
self.para = IntVar()
self.pan_d = IntVar()
...

 IntVar and StringVar: Special Tkinter variables that store data from input fields.
 Separate variables are declared for each item, total amounts, customer name, phone
number, and bill number.
5. Customer Details Section

python
Copy code
details = LabelFrame(self.root, text="Customer Details", ...)
cust_name = Label(details, text="Customer Name", ...)
cust_entry = Entry(details, ...)
...

 LabelFrame: Groups widgets related to customer details.


 Label: Displays text (e.g., "Customer Name").
 Entry: Creates input fields for customer name, contact number, and bill number.

6. Item Categories

The application divides items into three sections:

1. Medicines
2. Health Products
3. Hygiene Products

Each section is implemented as a LabelFrame with:

 Label: Displays the name of the product.


 Entry: Input fields linked to respective variables (e.g., self.para, self.pan_d) for
quantities.

Example:

python
Copy code
medicine = LabelFrame(self.root, text="Medicine", ...)
item1 = Label(medicine, text="Paracetamol(650mg)", ...)
item1_entry = Entry(medicine, textvariable=self.para).grid(...)

7. Bill Number Generation

python
Copy code
x = random.randint(1000, 9999)
self.bill_no.set(str(x))

 A random 4-digit bill number is generated and assigned to the bill_no variable.

How It Works

1. Customer Details Input:


o Users enter the customer name, contact number, and view a pre-generated bill
number.
2. Item Quantity Input:
o Users can input quantities for items in the "Medicine," "Health," and
"Hygiene" sections.
3. Interaction with Variables:
o Each input field updates a corresponding Tkinter variable (e.g., self.para for
"Paracetamol").
4. Database Integration:
o The application connects to a MySQL database where details like bill number,
customer name, and purchased items can be stored (though this part is not yet
implemented).
5. UI Structure:
o Uses LabelFrame widgets to group elements logically.
o Each product category is styled with colors and fonts for readability.

#=====================================================Billarea=========
=====================================================================
billarea=Frame(self.root,bd=10,relief=GROOVE,bg="#E5B4F3")
billarea.place(x=1010,y=188,width=330,height=372)

bill_title=Label(billarea,text="Bill Area",font=("Arial
Black",17),bd=7,relief=GROOVE,bg="#E5B4F3",fg="#6C3483").pack(fill=X)

scrol_y=Scrollbar(billarea,orient=VERTICAL)
self.txtarea=Text(billarea,yscrollcommand=scrol_y.set)
scrol_y.pack(side=RIGHT,fill=Y)
scrol_y.config(command=self.txtarea.yview)
self.txtarea.pack(fill=BOTH,expand=1)

1. Creating the Bill Area Frame

This section sets up the bill area where the generated bill will be displayed. It uses a Frame
widget to contain other elements:

 The frame has a styled border (bd=10, relief=GROOVE) and a background color
(bg="#E5B4F3").
 Positioned on the right side of the window (place(x=1010, y=188, width=330,
height=372)).

2. Adding the Bill Area Title

 A Label widget titled "Bill Area" is added to the top of the frame.
 The title uses a bold font (font=("Arial Black", 17)) and is centered across the
frame (pack(fill=X)).
3. Scrollbar for Text Area

 A vertical scrollbar (Scrollbar) is created for navigation in case the bill content
exceeds the visible area.
 The scrollbar is linked to the text area (command=self.txtarea.yview), enabling
synchronized scrolling.

4. Text Area

 A Text widget is used for displaying the bill content. This multiline text area allows
for detailed bill information, such as:
o Customer name and contact details.
o Purchased items with quantities and prices.
o Total amount and bill number.
 The text area is linked to the scrollbar (yscrollcommand=scrol_y.set) for smooth
navigation.
 It is configured to dynamically fill the frame space (fill=BOTH, expand=1).

Purpose of the Section

 This section is crucial for displaying the bill to the user in a readable and scrollable
format.
 It acts as the main output area for the billing software.
 #=====================================================StockArea==
=================================================================
===========
 def stock(self):

stock=Frame(self.root,bd=10,relief=GROOVE,bg="#E5B4F3")
 stock.place(x=1350,y=188,width=330,height=372)
 stock_title=Label(stock,text="Current
Stock",font=("Arial
Black",17),bd=7,relief=GROOVE,bg="#E5B4F3",fg="#6C3483").pack(fil
l=X)
 scrol_y=Scrollbar(stock,orient=VERTICAL)
 self.txtarea1=Text(stock,yscrollcommand=scrol_y.set)
 scrol_y.pack(side=RIGHT,fill=Y)
 scrol_y.config(command=self.txtarea.yview)
 self.txtarea1.pack(fill=BOTH,expand=1)

 self.txtarea1.insert(END,"\tMEDICINE CATAGORY\n")
 self.txtarea1.insert(END,"serial\tname\t\tquantity\
n")
 cur.execute("select * from medicine\n")
 data=cur.fetchall()
 for row in data:
 self.txtarea1.insert(END,f"{row[0]}\t{row[1]}\t\
t{row[3]}\n")

 self.txtarea1.insert(END,"\n\tHEALTH CATAGORY\n")
 self.txtarea1.insert(END,"serial\tname\t\tquantity\
n")
 cur.execute("select * from health\n")
 data=cur.fetchall()
 for row in data:
 self.txtarea1.insert(END,f"{row[0]}\t{row[1]}\t\
t{row[3]}\n")

 self.txtarea1.insert(END,"\n\tHYGIENE CATAGORY\n")
 self.txtarea1.insert(END,"serial\tname\t\tquantity\
n")
 cur.execute("select * from hygiene\n")
 data=cur.fetchall()
 for row in data:
 self.txtarea1.insert(END,f"{row[0]}\t{row[1]}\t\
t{row[3]}\n")

1. Creating the Stock Area

 A frame is created to display the current stock information (Frame(self.root)).


 The frame includes:
o Border and relief styling (bd=10, relief=GROOVE).
o Positioned at a specific location on the right (place(x=1350, y=188,
width=330, height=372)).

2. Adding the Stock Title

 A Label widget is used to display the title "Current Stock" at the top of the frame.
 The label's styling includes:
o Bold font (font=("Arial Black",17)).
o Colors for background and text (bg="#E5B4F3", fg="#6C3483").

3. Adding a Scrollable Text Area

 A Scrollbar widget is added for navigation in case the stock data exceeds the visible
area.
 The Text widget (self.txtarea1) is used to display stock data, such as:
o Categories (Medicine, Health, Hygiene).
o Item details (Serial number, Name, Quantity).
 The scrollbar is linked to the text area for seamless scrolling
(yscrollcommand=scrol_y.set).

4. Fetching Data from the Database

 SQL queries fetch data from tables (medicine, health, hygiene) in the database:
o cur.execute("select * from ...") retrieves all rows from each table.
o cur.fetchall() gets all results of the query.
 The data is formatted and inserted into the text area (self.txtarea1.insert):
o Column headers (e.g., "serial, name, quantity") are displayed first.
o A loop (for row in data) appends each row's details.

5. Organizing Stock by Categories

 The stock information is grouped into three categories:


1. Medicine Category: Displays items from the medicine table.
2. Health Category: Displays items from the health table.
3. Hygiene Category: Displays items from the hygiene table.
 Each category is visually separated for clarity.

Purpose of the Section

 This section is responsible for displaying the current stock inventory to the user.
 It helps in:
o Monitoring available stock for each category.
o Ensuring sufficient supply by tracking quantities.
 #=====================================================StockArea=
=================================================================
============
 def record(self):

record=Frame(self.root,bd=10,relief=GROOVE,bg="#E5B4F3")
 record.place(x=5,y=700,width=600,height=250)
 record_title=Label(record,text="Customer
Details",font=("Arial
Black",17),bd=7,relief=GROOVE,bg="#E5B4F3",fg="#6C3483").pack(fil
l=X)
 scrol_y=Scrollbar(record,orient=VERTICAL)
 self.txtarea2=Text(record,yscrollcommand=scrol_y.set)
 scrol_y.pack(side=RIGHT,fill=Y)
 scrol_y.config(command=self.txtarea.yview)
 self.txtarea2.pack(fill=BOTH,expand=1)

 self.txtarea2.insert(END,"\t\t\t2024-25\n")
 cur.execute("select date(sysdate())")
 a=cur.fetchall()
 if a: # Ensure data is returned
 b = a[0][0]
 cur.execute("INSERT INTO record VALUES (%s, %s, %s,
%s, %s)",(self.bill_no.get(), self.c_name.get(
 ), self.phone.get(), self.total_all_bill, str(b)))
 conn.commit()
 cur.execute("select * from record\n")
 data = cur.fetchall()
 self.txtarea2.insert(END,"\t\t\tCUSTOMER RECORDS\n")
 self.txtarea2.insert(END,"\nBill no\tName\t\t\tPhone\
t\tTotal\tDate\n")
 for row in data:
 self.txtarea2.insert(END, f"{row[0]}\t{row[1]}\t\
t\t{row[2]}\t\t{row[3]}\t{row[4]}\n")
 cur.execute("select count(purchase_value) as
total_customers,sum(purchase_value) as total_sale from record
where purchase_date = date(sysdate())")
 data = cur.fetchall()
 self.txtarea2.insert(END,f"today {data[0][0]}
customers visited\n")
 self.txtarea2.insert(END,f"today's total puchase
value is: {data[0][1]}")

1. Creating the Customer Details Section

 A frame is created to display customer records (Frame(self.root)).


 The frame includes:
o Border and styling (bd=10, relief=GROOVE).
o Positioned at the bottom-left of the application window (place(x=5, y=700,
width=600, height=250)).

2. Adding the Section Title

 A Label widget is used for the title "Customer Details".


 The label’s font, background, and text colors are styled for prominence.

3. Scrollable Text Area

 A Text widget (self.txtarea2) is added to display the customer details.


 A vertical Scrollbar is attached for navigation when records exceed the visible area.
4. Displaying Date

 The current date is fetched using an SQL query:

sql
Copy code
select date(sysdate())

 If the query returns a result, the date is stored and used in further processing.

5. Storing Customer Data

 A new record is inserted into the record database table with the following values:
o Bill number (self.bill_no.get()).
o Customer name (self.c_name.get()).
o Phone number (self.phone.get()).
o Total bill value (self.total_all_bill).
o Purchase date (fetched from the database).
 The changes are committed to the database to save the new record.

6. Fetching and Displaying Records

 All customer records are fetched from the record table:

sql
Copy code
select * from record

 The data is formatted and displayed in the text area with headers (e.g., "Bill no,
Name, Phone, Total, Date").

7. Daily Summary

 A summary of the day's customer activity is calculated using SQL:

sql
Copy code
select count(purchase_value) as total_customers, sum(purchase_value)
as total_sale
from record
where purchase_date = date(sysdate())

 The summary includes:


o Total number of customers who visited today.
o Total purchase value for the day.
 These statistics are appended to the text area for quick reference.

Purpose of the Section

 This section provides a comprehensive view of customer data:


o Individual purchase records.
o Daily customer count and total sales.
 It helps store owners analyze and track business performance.

#=================================================billing
menu===================================================================
======================
billing_menu=LabelFrame(self.root,text="Billing
Summary",font=("Arial
Black",12),relief=GROOVE,bd=10,bg="#A569BD",fg="white")
billing_menu.place(x=0,y=560,relwidth=2,height=137)

total_medicine=Label(billing_menu,text="Total Medicine
Price",font=("Arial
Black",11),bg="#A569BD",fg="white").grid(row=0,column=0)

total_medicine_entry=Entry(billing_menu,width=30,borderwidth=2,textvari
able=self.total_med).grid(row=0,column=1,padx=10,pady=7)

total_health=Label(billing_menu,text="Total Health
Price",font=("Arial
Black",11),bg="#A569BD",fg="white").grid(row=1,column=0)

total_health_entry=Entry(billing_menu,width=30,borderwidth=2,textvariab
le=self.total_hel).grid(row=1,column=1,padx=10,pady=7)

total_hygiene=Label(billing_menu,text=" Total Hygiene


Price",font=("Arial
Black",11),bg="#A569BD",fg="white").grid(row=2,column=0)

total_hygiene_entry=Entry(billing_menu,width=30,borderwidth=2,textvaria
ble=self.total_hyg).grid(row=2,column=1,padx=10,pady=7)

tax_medicine=Label(billing_menu,text="Medicine
Tax",font=("Arial
Black",11),bg="#A569BD",fg="white").grid(row=0,column=2)

tax_medicine_entry=Entry(billing_menu,width=30,borderwidth=2,textvariab
le=self.a).grid(row=0,column=3,padx=10,pady=7)
tax_health=Label(billing_menu,text="Health Tax",font=("Arial
Black",11),bg="#A569BD",fg="white").grid(row=1,column=2)

tax_health_entry=Entry(billing_menu,width=30,borderwidth=2,textvariable
=self.b).grid(row=1,column=3,padx=10,pady=7)

tax_hygiene=Label(billing_menu,text="Hygine Tax",font=("Arial
Black",11),bg="#A569BD",fg="white").grid(row=2,column=2)

tax_hygiene_entry=Entry(billing_menu,width=30,borderwidth=2,textvariabl
e=self.c).grid(row=2,column=3,padx=10,pady=7)

button_frame=Frame(billing_menu,bd=7,relief=GROOVE,bg="#6C3483")
button_frame.place(x=830,width=780,height=95)

button_total=Button(button_frame,text="Total Bill",font=("Arial
Black",15),
pady=10,bg="#E5B4F3",fg="#6C3483",command=lambda:total(self)
).grid(row=0,column=0,padx=12)
button_clear=Button(button_frame,text="Clear
Field",font=("Arial Black",15)
,pady=10,bg="#E5B4F3",fg="#6C3483",command=lambda:clear(self)
).grid(row=0,column=1,padx=10,pady=6)
button_exit=Button(button_frame,text="Exit",font=("Arial
Black",15)

,pady=10,bg="#E5B4F3",fg="#6C3483",width=8,command=lambda:exit1(self)
).grid(row=0,column=2,padx=10,pady=6)
intro(self)
button_stock=Button(button_frame,text="Current
Stock",font=("Arial Black",15),
pady=10,bg="#E5B4F3",fg="#6C3483",command=lambda:stock(self)
).grid(row=0,column=3,padx=12)
button_record=Button(button_frame,text="Record",font=("Arial
Black",15),
pady=10,bg="#E5B4F3",fg="#6C3483",command=lambda:record(self)
).grid(row=0,column=4,padx=12)

1. Creating the Billing Summary Section

 A LabelFrame is created to encapsulate all the widgets for the Billing Summary
section.
o It includes labels, entry fields, and action buttons.
o Positioned near the bottom of the application window (place(x=0, y=560,
relwidth=2, height=137)).
o Styled with a purple background and white text for a clean and vibrant look.
2. Displaying Total Prices

 Labels and entry fields are added for:


o Total Medicine Price
o Total Health Price
o Total Hygiene Price
 Each entry field uses a textvariable to bind the widget to variables
(self.total_med, self.total_hel, self.total_hyg).
 These variables are dynamically updated and store the corresponding values.

3. Displaying Taxes

 Labels and entry fields for tax amounts include:


o Medicine Tax
o Health Tax
o Hygiene Tax
 textvariable bindings (self.a, self.b, self.c) allow these fields to reflect the
calculated tax values.

4. Adding Action Buttons

 A separate Frame (button_frame) organizes the buttons at the bottom of the billing
summary.
o Positioned within the billing menu frame (place(x=830, width=780,
height=95)).
 Buttons include:
o Total Bill: Triggers the total(self) function to calculate the total bill.
o Clear Field: Calls the clear(self) function to reset all fields in the section.
o Exit: Executes the exit1(self) function to close the application.
o Current Stock: Launches the stock(self) function to display current stock
details.
o Record: Opens the record(self) function to view customer records.

5. Overall Functionality

 This section provides a user-friendly interface for managing billing operations:


o Input fields for total prices and taxes.
o Action buttons for performing core functionalities (e.g., calculating totals,
clearing fields, or accessing stock and records).
 The use of textvariable bindings ensures that calculations and updates are
synchronized across widgets.

 def total(self):
 if (self.c_name.get=="" or self.phone.get()==""):
 messagebox.showerror("Error", "Fill the complete Customer
Details!!")

 #=================================================updating
values in
database=========================================================
================================
 cur.execute("update medicine set qty=qty-%s where intemno=
%s"%(self.para.get(),1))
 cur.execute("update medicine set qty=qty-%s where intemno=
%s"%(self.pan_d.get(),2))
 cur.execute("update medicine set qty=qty-%s where intemno=
%s"%(self.saridon.get(),3))
 cur.execute("update medicine set qty=qty-%s where intemno=
%s"%(self.thyrox.get(),4))
 cur.execute("update medicine set qty=qty-%s where intemno=
%s"%(self.ambizyme.get(),5))
 cur.execute("update medicine set qty=qty-%s where intemno=
%s"%(self.ecosprin.get(),6))
 cur.execute("update medicine set qty=qty-%s where intemno=
%s"%(self.broncophil.get(),7))
 cur.execute("update health set qty=qty-%s where item_no=%s"%
(self.multivitamin.get(),1))
 cur.execute("update health set qty=qty-%s where item_no=%s"%
(self.protein.get(),2))
 cur.execute("update health set qty=qty-%s where item_no=%s"%
(self.ors.get(),3))
 cur.execute("update health set qty=qty-%s where item_no=%s"%
(self.baby.get(),4))
 cur.execute("update health set qty=qty-%s where item_no=%s"%
(self.endura.get(),5))
 cur.execute("update health set qty=qty-%s where item_no=%s"%
(self.beta_g.get(),6))
 cur.execute("update health set qty=qty-%s where item_no=%s"%
(self.vaseline.get(),7))
 cur.execute("update hygiene set qty=qty-%s where item_no=%s"%
(self.diaper.get(),1))
 cur.execute("update hygiene set qty=qty-%s where item_no=%s"%
(self.pad.get(),2))
 cur.execute("update hygiene set qty=qty-%s where item_no=%s"%
(self.beta_d.get(),3))
 cur.execute("update hygiene set qty=qty-%s where item_no=%s"%
(self.bandaid.get(),4))
 cur.execute("update hygiene set qty=qty-%s where item_no=%s"%
(self.cotton.get(),5))
 cur.execute("update hygiene set qty=qty-%s where item_no=%s"%
(self.sanitizer.get(),6))
 cur.execute("update hygiene set qty=qty-%s where item_no=%s"%
(self.wipes.get(),7))
 conn.commit()

#================================================================
=================================================================
====================================
 self.pa=self.para.get()*120
 self.pan=self.pan_d.get()*40
 self.sa=self.saridon.get()*10
 self.th=self.thyrox.get()*20
 self.am=self.ambizyme.get()*30
 self.eco=self.ecosprin.get()*60
 self.bro=self.broncophil.get()*15
 total_medicine_price=(
 self.pa+
 self.pan+
 self.sa+
 self.th+
 self.am+
 self.eco+
 self.bro)
 self.total_med.set(str(total_medicine_price)+" Rs")
 self.a.set(str(round(total_medicine_price*0.05,3))+" Rs")


 self.mu=self.multivitamin.get()*42
 self.pro=self.protein.get()*120
 self.o=self.ors.get()*113
 self.bab=self.baby.get()*160
 self.en=self.endura.get()*55
 self.be=self.beta_g.get()*480
 self.va=self.vaseline.get()*76
 total_health_price=(
 self.mu+
 self.pro+
 self.o+
 self.bab+
 self.en+
 self.be+
 self.va)

 self.total_hel.set(str(total_health_price)+" Rs")
 self.b.set(str(round(total_health_price*0.10,3))+" Rs")

 self.di=self.diaper.get()*30
 self.p=self.pad.get()*180
 self.bet=self.beta_d.get()*130
 self.ban=self.bandaid.get()*60
 self.co=self.cotton.get()*80
 self.san=self.sanitizer.get()*200
 self.w=self.wipes.get()*20
 cur.execute("update hygiene set qty=qty-%s where item_no=%s"%
(self.diaper.get(),1))

 total_hygiene_price=(
 self.di+
 self.p+
 self.bet+
 self.ban+
 self.co+
 self.san+
 self.w)

 self.total_hyg.set(str(total_hygiene_price)+" Rs")
 self.c.set(str(round(total_hygiene_price*0.10,3))+" Rs")
 self.total_all_bill=(total_medicine_price+
 total_health_price+
 total_hygiene_price+
 (round(total_medicine_price*0.05,3))+
 (round(total_health_price*0.10,3))+
 (round(total_hygiene_price*0.05,3)))
 self.total_all_bil=str(self.total_all_bill)+" Rs"
 billarea(self)

Explanation of the Code

1. Customer Validation

 The function first checks if the customer's name (self.c_name) or phone number
(self.phone) is empty.
o If either is missing, an error message box (messagebox.showerror) prompts
the user to fill in the details.

2. Updating Database Quantities

 The code updates the quantities of items in the database based on the customer's
purchase.
o Executes multiple SQL UPDATE statements to reduce stock (qty) in the
medicine, health, and hygiene tables.
o Each item is referenced by its unique item_no or intemno.
o The quantity to be deducted is taken from the respective fields (e.g.,
self.para.get() for Paracetamol).
 Changes are committed to the database using conn.commit().

3. Calculating Medicine Price and Tax

 Medicine Prices:
o Individual prices for medicines are calculated by multiplying quantities
(get() values) with their respective rates (e.g., self.para.get() * 120 for
Paracetamol at ₹120 per unit).
o Total medicine price is computed by summing these individual prices.
 Medicine Tax:
o Calculated as 5% of the total medicine price and rounded to 3 decimal places.
o Stored in self.a and displayed as a string with "Rs" appended.

4. Calculating Health Product Price and Tax

 Health Product Prices:


o Similar to medicines, individual and total prices are computed for health
products.
o Rates vary for items (e.g., self.protein.get() * 120 for Protein Powder at
₹120 per unit).
 Health Product Tax:
o Calculated at 10% of the total health product price and stored in self.b.

5. Calculating Hygiene Product Price and Tax

 Hygiene Product Prices:


o Individual and total prices for hygiene items are computed (e.g.,
self.diaper.get() * 30 for Diapers at ₹30 per unit).
 Hygiene Tax:
o Set at 10% of the total hygiene price and stored in self.c.

6. Computing the Total Bill

 The total bill amount combines:


o Total prices for medicines, health products, and hygiene products.
o Their respective taxes.
 The final total is formatted as a string with "Rs" appended and stored in
self.total_all_bil.
7. Generating the Bill

 Calls the billarea(self) function to display the calculated bill in a dedicated


section.

def intro(self):
self.txtarea.delete(1.0,END)
self.txtarea.insert(END,"\tWELCOME TO MARVEL PHARMACY\n\tPhone-
No.739275410")
self.txtarea.insert(END,f"\n\nBill no. : {self.bill_no.get()}")
self.txtarea.insert(END,f"\nCustomer Name : {self.c_name.get()}")
self.txtarea.insert(END,f"\nPhone No. : {self.phone.get()}")
self.txtarea.insert(END,"\n====================================\n")
self.txtarea.insert(END,"\nProduct\t\tQty\tPrice\n")
self.txtarea.insert(END,"\n====================================\n")

Explanation of the intro Function

1. Clearing the Text Area

 The function begins by clearing the existing content in the self.txtarea text
widget using:
o self.txtarea.delete(1.0, END) which deletes all text from the first line to
the end.

2. Adding Welcome Message

 A welcome message for "Marvel Pharmacy" is inserted into the text area.
o Includes the pharmacy name and contact number: "WELCOME TO MARVEL
PHARMACY\nPhone-No.739275410".

3. Inserting Billing Details

 The function appends details related to the customer and bill:


o Bill no.: Retrieved from self.bill_no.get() and added dynamically.
o Customer Name: Retrieved from self.c_name.get().
o Phone No.: Retrieved from self.phone.get().

4. Formatting the Bill Header


 Adds a header section for the bill:
o "====================================": Used as a separator for
readability.
o Column titles: "Product\t\tQty\tPrice" indicating the structure of the
billing table.

5. Final Layout

 The structure creates a professional-looking bill that:


o Welcomes the customer.
o Displays their details.
o Prepares the text area for the product details (to be inserted later).

def billarea(self):
intro(self)
if self.para.get()!=0:
self.txtarea.insert(END,f"Paracetamol(650 mg)\t\t
{self.para.get()}\t{self.pa}\n")
if self.pan_d.get()!=0:
self.txtarea.insert(END,f"Pan-D(1 strip)\t\t
{self.pan_d.get()}\t{self.pan}\n")
if self.saridon.get()!=0:
self.txtarea.insert(END,f"Saridon(1 strip\t\t
{self.saridon.get()}\t{self.sa}\n")
if self.thyrox.get()!=0:
self.txtarea.insert(END,f"Thyrox(50mg)\t\t {self.thyrox.get()}\
t{self.th}\n")
if self.ambizyme.get()!=0:
self.txtarea.insert(END,f"Ambizyme\t\t {self.ambizyme.get()}\
t{self.am}\n")
if self.ecosprin.get()!=0:
self.txtarea.insert(END,f"Ecosprin(75mg)\t\t
{self.ecosprin.get()}\t{self.eco}\n")
if self.broncophil.get()!=0:
self.txtarea.insert(END,f"Broncophil(100mg)\t\t
{self.broncophil.get()}\t{self.bro}\n")
if self.multivitamin.get()!=0:
self.txtarea.insert(END,f"Multivitamin\t\t
{self.multivitamin.get()}\t{self.mu}\n")
if self.protein.get()!=0:
self.txtarea.insert(END,f"Protein-X\t\t {self.protein.get()}\
t{self.pro}\n")
if self.ors.get()!=0:
self.txtarea.insert(END,f"ORS\t\t {self.ors.get()}\t{self.o}\
n")
if self.baby.get()!=0:
self.txtarea.insert(END,f"Himalaya-Powder(baby)\t\t
{self.baby.get()}\t{self.bab}\n")
if self.endura.get()!=0:
self.txtarea.insert(END,f"Endura-Mass\t\t {self.endura.get()}\
t{self.en}\n")
if self.beta_g.get()!=0:
self.txtarea.insert(END,f"Betadine-Gargle\t\t
{self.beta_g.get()}\t{self.be}\n")
if self.vaseline.get()!=0:
self.txtarea.insert(END,f"Vaseline\t\t {self.vaseline.get()}\
t{self.va}\n")
if self.diaper.get()!=0:
self.txtarea.insert(END,f"Baby-Diaper\t\t {self.diaper.get()}\
t{self.di}\n")
if self.pad.get()!=0:
self.txtarea.insert(END,f"Sanitary-Pad\t\t {self.pad.get()}\
t{self.p}\n")
if self.beta_d.get()!=0:
self.txtarea.insert(END,f"Betadine\t\t {self.beta_d.get()}\
t{self.bet}\n")
if self.bandaid.get()!=0:
self.txtarea.insert(END,f"Band-Aid\t\t {self.bandaid.get()}\
t{self.ban}\n")
if self.cotton.get()!=0:
self.txtarea.insert(END,f"Cotton\t\t {self.cotton.get()}\
t{self.co}\n")
if self.sanitizer.get()!=0:
self.txtarea.insert(END,f"Sanitizer\t\t {self.sanitizer.get()}\
t{self.san}\n")
if self.wipes.get()!=0:
self.txtarea.insert(END,f"Baby-Wipes\t\t {self.wipes.get()}\
t{self.w}\n")

self.txtarea.insert(END,f"------------------------------------\n")
if self.a.get()!="0.0 Rs":
self.txtarea.insert(END,f"Total Medicine Tax : {self.a.get()}\
n")
if self.b.get()!="0.0 Rs":
self.txtarea.insert(END,f"Total Health Tax : {self.b.get()}\n")
if self.c.get()!="0.0 Rs":
self.txtarea.insert(END,f"Total Hygiene Tax : {self.c.get()}\
n")
self.txtarea.insert(END,f"Total Bill Amount : {self.total_all_bil}\
n")
self.txtarea.insert(END,f"------------------------------------\n")

Explanation of the billarea Function


1. Calling the Intro Function

 The function first calls intro(self) to initialize the bill with the customer's details
and the table header.

2. Inserting Product Information

 The function then checks each item (e.g., para, pan_d, saridon, etc.) to see if its
quantity is greater than 0. If it is, it inserts the product details (name, quantity, and
price) into the txtarea widget.
o Format: "Product Name\t\t Quantity\t Price"
o For example:
 If para.get() is not zero, the line "Paracetamol(650 mg)\t\t
{self.para.get()}\t{self.pa}" is inserted.
 The following product categories are checked and inserted in the order of priority:
o Medicines: Paracetamol, Pan-D, Saridon, Thyrox, Ambizyme, Ecosprin,
Broncophil.
o Health: Multivitamin, Protein-X, ORS, Himalaya Powder, Endura Mass,
Betadine Gargle, Vaseline.
o Hygiene: Diaper, Sanitary Pad, Betadine, Band-Aid, Cotton, Sanitizer, Baby
Wipes.

3. Formatting and Inserting Tax Information

 After listing the products, the function checks if there is any tax for each category
(medicine, health, hygiene).
o If a tax is applied (i.e., not zero), the tax for that category is displayed.
o The format used is "Total [Category] Tax : [tax amount]".

4. Inserting Total Bill

 The total bill amount is inserted at the end with the format:
o "Total Bill Amount : [total amount]".

5. Divider Line

 A divider line ("------------------------------------") is inserted between


the items and the totals to improve readability.
Considerations for Improvement

1. Handling Empty Quantities


o Since all checks for self.[item].get() are for non-zero values, it is
assumed that items with a quantity of zero are not included. However, if you
expect some items to sometimes have zero quantities but still want them to
show as zero or not listed, you can update the code to handle them differently.
2. Enhanced Readability
o You could add additional space or formatting to the list of items, such as
aligning the quantity and price columns to make the bill more structured.
o Example:

python
Copy code
self.txtarea.insert(END, f"Paracetamol(650 mg)\t\t
{str(self.para.get()).rjust(2)}\t {str(self.pa).rjust(3)}\n")

3. Error Handling
o Consider adding error handling for cases where database retrieval fails or there
is an issue with product data.
4. Improved Tax Formatting
o The tax information could be shown in a more structured format, such as by
calculating a subtotal before taxes.

Final Note

The function is useful for displaying a detailed, formatted bill in a text area, listing products,
quantities, prices, taxes, and the total bill amount. The structure is clear, and it's easy to
follow when reading the output on the GUI.

def clear(self):
# Clear the text area
self.txtarea.delete(1.0, END)

# Reset product quantities


self.para.set(0)
self.pan_d.set(0)
self.saridon.set(0)
self.thyrox.set(0)
self.ambizyme.set(0)
self.ecosprin.set(0)
self.broncophil.set(0)
self.multivitamin.set(0)
self.protein.set(0)
self.ors.set(0)
self.baby.set(0)
self.endura.set(0)
self.beta_g.set(0)
self.vaseline.set(0)
self.diaper.set(0)
self.pad.set(0)
self.beta_d.set(0)
self.bandaid.set(0)
self.cotton.set(0)
self.sanitizer.set(0)
self.wipes.set(0)

# Reset totals and taxes


self.total_med.set(0)
self.total_hel.set(0)
self.total_hyg.set(0)
self.a.set(0)
self.b.set(0)
self.c.set(0)

# Reset customer details


self.c_name.set("")
self.bill_no.set(0)
self.phone.set("")

1. Clearing the Text Area

 self.txtarea.delete(1.0, END) is used to clear the entire text area from the
beginning (index 1.0) to the end (END).

2. Resetting Product Quantities

 The next set of lines resets the values of all product quantities (e.g.,
self.para.set(0), self.pan_d.set(0)), setting them back to zero for each
product.
 This ensures that the quantity for each product is cleared and ready to be updated for
the next customer.

3. Resetting Total Values

 self.total_med.set(0), self.total_hel.set(0), self.total_hyg.set(0)


reset the total values for medicine, health, and hygiene categories to zero.
 The tax-related fields (self.a.set(0), self.b.set(0), self.c.set(0)) are also
reset to 0 to ensure that tax calculations don't carry over.

4. Resetting Customer Details

 self.c_name.set(0), self.bill_no.set(0), and self.phone.set(0) reset the


customer details (name, phone number, and bill number) to zero or empty state.
def exit1(self):
self.root.destroy()

root=Tk()
obj=Bill_App(root)
root.mainloop()

Explanation:

 self.root.destroy(): This line calls the destroy method on the Tk instance, which
closes the main window and effectively terminates the application.
 root=Tk(): This line initializes the Tkinter root window, which is the main window
for the application.
 obj=Bill_App(root): This creates an instance of the Bill_App class and passes the
root window to it. This ensures that your Bill_App class has access to the Tkinter
root window.
 root.mainloop(): This starts the Tkinter event loop, which keeps the application
running and waits for user interactions (e.g., button clicks).

OUTPUT
Conclusion:

Overview of the Project:


The "Marvel Pharmacy Billing System" is a desktop-based application built using Python and
Tkinter. The primary purpose of this project is to automate the process of billing and
inventory management in a pharmacy. The application helps pharmacy staff efficiently
manage sales transactions, maintain accurate stock levels, and compute the total bill with
taxes for various product categories, including medicines, health products, and hygiene items.

Key Features:

1. Product Management:
o Allows entry of quantities for various products such as medicines, health products,
and hygiene items.
o Tracks stock levels and automatically updates quantities after each sale.

2. Billing and Calculation:


o Computes the total price for the items purchased.
o Calculates applicable taxes for medicines, health products, and hygiene items.
o Displays the total amount due, including taxes.

3. Stock Management:
o Updates inventory upon product sale by reducing the quantity of sold items in the
database.
o Displays real-time stock levels to ensure that pharmacy staff can monitor inventory.

4. User-Friendly Interface:
o The GUI is intuitive and simple to navigate, designed with Tkinter for ease of use.
o Provides a clear and organized billing summary for customers, with options to print
or exit the bill.

5. Error Handling:
o The system includes error checks to ensure customer details are entered before
proceeding with the bill.
o It prompts for missing details and prevents accidental actions like incomplete billing.

6. Customizable for Future Enhancements:


o The current system can be expanded to include features such as product search,
reports generation, and multiple billing formats.
o The database connection can be adapted to use more robust systems, like MySQL or
PostgreSQL, for larger-scale applications.

Benefits:

 Efficiency in Operations:
The automated billing system significantly reduces human errors and speeds up the
transaction process, making it easier for pharmacy staff to focus on customer service.
 Accurate Tax Calculations:
By calculating taxes based on product categories (medicines, health, and hygiene), the
system ensures compliance with local tax regulations and provides transparency in
billing.
 Stock Tracking:
The application helps in tracking inventory levels in real-time, which reduces the
chances of over-selling products and allows for timely reordering.
 Clear Billing Summary:
The detailed and clear billing summary ensures that customers are aware of the
products they are purchasing, along with the total cost and taxes applied.

Conclusion:

This "Marvel Pharmacy Billing System" serves as an efficient, user-friendly tool for
automating the sales and stock management processes in a pharmacy setting. The application
helps streamline operations, reduce human error, and improve customer satisfaction by
providing quick and accurate billing information. By integrating basic inventory and tax
management, this project offers a solid foundation for a pharmacy management system that
can be further enhanced with additional features such as invoice generation, multi-user
support, and enhanced database management.

Future Enhancements:

 Invoice Generation: Integrating a feature that allows for PDF or print invoice generation.
 Product Search and Sorting: Implementing a search feature to allow easy product look-up by
name or category.
 Multi-User Support: Enabling multiple user access for different roles (e.g., cashiers,
managers).
 Data Analytics: Incorporating data analytics to generate reports on sales trends and stock
performance.

THANK YOU

You might also like