0% found this document useful (0 votes)
5 views6 pages

Cs Project Code

This document contains a Python script using Tkinter to create a simple billing software application. Users can dynamically add items with their names, prices, and quantities, and calculate the total price of the items. The application also includes functionality to clear all fields and display the bill in a text widget.
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)
5 views6 pages

Cs Project Code

This document contains a Python script using Tkinter to create a simple billing software application. Users can dynamically add items with their names, prices, and quantities, and calculate the total price of the items. The application also includes functionality to clear all fields and display the bill in a text widget.
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

CODE

import tkinter as tk
from tkinter import messagebox

# Function to calculate the total


def calculate_total():
total_price = 0
bill_text.delete(1.0, [Link]) # Clear the bill area
bill_text.insert([Link], "Item\tQty\tPrice\n")
bill_text.insert([Link], "-"*30 + "\n")

for item in items:


name = item['name'].get()
price = float(item['price'].get())
qty = int(item['quantity'].get())
total_price += price * qty
bill_text.insert([Link], f"{name}\t{qty}\t{price * qty}\n")

bill_text.insert([Link], "-"*30 + "\n")


bill_text.insert([Link], f"Total Price: \t{total_price}\n")

# Function to clear all fields


def clear_all():
for item in items:
item['name'].set("")
item['price'].set(0)
item['quantity'].set(0)
bill_text.delete(1.0, [Link])

# Create main window


root = [Link]()
[Link]("Billing Software")
[Link]("600x500")

# List to store item information


items = []

# Function to add item fields dynamically


def add_item():
item_frame = [Link](root)
item_frame.pack(pady=5)

name_var = [Link]()
price_var = [Link]()
quantity_var = [Link]()
# Item name entry
[Link](item_frame, text="Item Name:").grid(row=0, column=0)
[Link](item_frame, textvariable=name_var,
width=20).grid(row=0, column=1)

# Item price entry


[Link](item_frame, text="Price:").grid(row=0, column=2)
[Link](item_frame, textvariable=price_var,
width=10).grid(row=0, column=3)

# Item quantity entry


[Link](item_frame, text="Quantity:").grid(row=0, column=4)
[Link](item_frame, textvariable=quantity_var,
width=10).grid(row=0, column=5)

# Append item details to the list


[Link]({
'name': name_var,
'price': price_var,
'quantity': quantity_var
})

# Add item button


add_item_button = [Link](root, text="Add Item",
command=add_item)
add_item_button.pack(pady=10)

# Create a text widget to display the bill


bill_text = [Link](root, height=15, width=60, borderwidth=2,
relief=[Link])
bill_text.pack(pady=10)

# Buttons for calculating total and clearing fields


calculate_button = [Link](root, text="Calculate Total",
command=calculate_total)
calculate_button.pack(pady=5)

clear_button = [Link](root, text="Clear All", command=clear_all)


clear_button.pack(pady=5)

# Run the application


[Link]()
OUTPUT

You might also like