Hello friends, in this article, we will see Sales Management System Project in Python. We will add basic features like adding products, deleting products, updating products, and viewing all products. We have used inbuilt SQLite3 for database purposes and tkinter for GUI.
Project overview: Sales Management System Project in Python
Project Name: | Sales Management System Project in Python |
Abstract: | We will create a GUI-based application that can be used to track the sales of any shop or store |
Language Used: | Python |
IDE: | VS Code(recommended) |
Database: | SQLite3 |
Type: | GUI Application |
Recommended for: | Beginners and Intermediates of Tkinter |
Prerequisites
- Basic knowledge of Python programming language
- Tkinter
- SQLite3
Requirements and setup
You should have the latest version of Python installed in your system. We have used SQLite3 and tkinter, both come built-in with Python so no need to install them separately. You can use any IDE, we have used VS code. There are no separate files/resources used so you can copy our code and run it directly on your computer and we hope it will run without any errors.
Features
- Basic features: Adding a product, Updating a product, View all products list, and Deleting a producting
- Auto calculation: When you will fill in entries to add or update a product, you can verify all your entries and it will auto-calculate prices for total sales.
- Updated data: Whenever you will perform any CRUD operation(Adding, viewing, updating, or deleting a product), the sales management system app will auto-refresh the updated data.
- Exception handling: We have created this Sales Management System Project in Python in such a way that it will not crash at any point as we have handled wrong entries or any other exceptions using exception handling in Python.
- Message/alert: Whenever you perform an operation then you will get an alert message for the operation, if there is any error then you will get the error message.
Coding Sales Management System Project in Python
We have used comments for a better explanation of sub-parts. You can copy and paste this code and directly run it.
# importing libraries import tkinter as tk from tkinter import messagebox import sqlite3 # creating window root_window = tk.Tk() root_window.title("CopyAssignment Sales Management") root_window.geometry("720x750") # creating entry variables name_entry_text = tk.StringVar() id_entry_text = tk.StringVar() quantity_sold_entry_text = tk.StringVar() quantity_left_entry_text = tk.StringVar() price_entry_text = tk.StringVar() today_sales_quantity_entry_text = tk.StringVar() today_sales_total_price_entry_text = tk.StringVar() week_sales_quantity_entry_text = tk.StringVar() week_sales_total_price_entry_text = tk.StringVar() month_sales_quantity_entry_text = tk.StringVar() month_sales_total_price_entry_text = tk.StringVar() delete_entry = tk.StringVar() # creating the entries name_entry = tk.Entry(root_window, textvariable=name_entry_text) id_entry = tk.Entry(root_window, textvariable=id_entry_text) quantity_sold_entry = tk.Entry(root_window, textvariable=quantity_sold_entry_text) quantity_left_entry = tk.Entry(root_window, textvariable=quantity_left_entry_text) price_entry = tk.Entry(root_window, textvariable=price_entry_text) today_sales_quantity_entry = tk.Entry(root_window, textvariable=today_sales_quantity_entry_text) today_sales_total_price_entry = tk.Entry(root_window, textvariable=today_sales_total_price_entry_text) week_sales_quantity_entry = tk.Entry(root_window, textvariable=week_sales_quantity_entry_text) week_sales_total_price_entry = tk.Entry(root_window, textvariable=week_sales_total_price_entry_text) month_sales_quantity_entry = tk.Entry(root_window, textvariable=month_sales_quantity_entry_text) month_sales_total_price_entry = tk.Entry(root_window, textvariable=month_sales_total_price_entry_text) delete_entry = tk.Entry(root_window, textvariable=delete_entry, width=20) delete_entry.grid(row=6, column=3, padx=10, columnspan=3, rowspan=2) delete_entry.insert(0, 'Enter id to delete') # create the labels name_label = tk.Label(root_window, text="Product name") id_label = tk.Label(root_window, text="Product ID") quantity_sold_label = tk.Label(root_window, text="Quantity sold") quantity_left_label = tk.Label(root_window, text="Quantity left") price_label = tk.Label(root_window, text="Price") today_sales_quantity_label = tk.Label(root_window, text="Today's Sales(quantity)") today_sales_total_price_label = tk.Label(root_window, text="Today's Sales(Total Price)") week_sales_quantity_label = tk.Label(root_window, text="Week Sales(quantity)") week_sales_total_price_label = tk.Label(root_window, text="Week Sales(Total Price)") month_sales_quantity_label = tk.Label(root_window, text="Month Sales(quantity)") month_sales_total_price_label = tk.Label(root_window, text="Month Sales(Total Price)") product_list_label = tk.Label(root_window, text='Product List', font=(30), borderwidth=1, relief="solid", width=50) product_list_label.grid(row=12, column=0, columnspan=50, pady=20) pdt_name = tk.Label(root_window, text='Product Name', borderwidth=1, relief="solid") pdt_id = tk.Label(root_window, text='Product ID', borderwidth=1, relief="solid") pdt_price = tk.Label(root_window, text='Product Price', borderwidth=1, relief="solid") pdt_sales_quantity = tk.Label(root_window, text="Today's Sales(Quantity)", borderwidth=1, relief="solid") # creating functions def Refresh(): conn = sqlite3.connect('database.db') cursor = conn.cursor() cursor.execute("CREATE TABLE IF NOT EXISTS products (name TEXT, id TEXT PRIMARY KEY, quantitySold TEXT, quantityLeft TEXT, price TEXT, todaySalesQuantity TEXT, todaySalesTotalPrice TEXT, weekSalesQuantity TEXT, weekSalesTotalPrice TEXT, monthSalesQuantity TEXT, monthSalesTotalPrice TEXT)") cursor.execute('SELECT * FROM products') products = cursor.fetchall() for i in range(len(products)): tk.Label(root_window, text=products[i][0]).grid(row=i+14, column=0) tk.Label(root_window, text=products[i][1]).grid(row=i+14, column=1) tk.Label(root_window, text=products[i][4]).grid(row=i+14, column=2) tk.Label(root_window, text=products[i][5]).grid(row=i+14, column=3) conn.close() def show_message(title, message): messagebox.showerror(title, message) def add_product(): try: conn = sqlite3.connect("database.db") cursor = conn.cursor() cursor.execute("INSERT INTO products (name, id, quantitySold, quantityLeft, price, todaySalesQuantity, todaySalesTotalPrice, weekSalesQuantity, weekSalesTotalPrice, monthSalesQuantity, monthSalesTotalPrice) VALUES (?, ?, ?, ?,?,?,?,?,?,?,?)", (str(name_entry_text.get()), str(id_entry_text.get()), str(quantity_sold_entry_text.get()), str(quantity_left_entry_text.get()), str(price_entry_text.get()), str(today_sales_quantity_entry_text.get()), str(today_sales_total_price_entry_text.get()), str(week_sales_quantity_entry_text.get()), str(week_sales_total_price_entry_text.get()), str(month_sales_quantity_entry_text.get()), str(month_sales_total_price_entry_text.get()))) conn.commit() except sqlite3.Error as e: show_message('Sqlite error', e) finally: Refresh() conn.close() def delete_product(): try: conn = sqlite3.connect("database.db") cursor = conn.cursor() cursor.execute('SELECT * FROM products') cursor.execute("DELETE FROM products WHERE id = ?", (str(delete_entry.get()))) conn.commit() show_message('Success', 'Product deleted') conn.close() Refresh() except sqlite3.Error as e: show_message('Sqlite error', e) finally: conn.close() Refresh() def update(): price = price_entry_text.get() quantity_sold = quantity_sold_entry_text.get() quantity_left = quantity_left_entry_text.get() today_sales_quantity = today_sales_quantity_entry_text.get() week_sales_quantity = week_sales_quantity_entry_text.get() month_sales_quantity = month_sales_quantity_entry_text.get() if len(price) < 1 or len(quantity_sold) < 1 or len(quantity_left) < 1 or len(today_sales_quantity) < 1 or len(week_sales_quantity) < 1 or len(month_sales_quantity) < 1: show_message('Python error!', 'Please enter values for all fields') return try: price = int(price) quantity_sold = int(quantity_sold) quantity_left = int(quantity_left) today_sales_quantity = int(today_sales_quantity) week_sales_quantity = int(week_sales_quantity) month_sales_quantity = int(month_sales_quantity) conn = sqlite3.connect('database.db') c = conn.cursor() c.execute("UPDATE products SET name=?, id=?, quantitySold=?, quantityLeft=?, price=?, todaySalesQuantity=?, todaySalesTotalPrice=?, weekSalesQuantity=?, weekSalesTotalPrice=?, monthSalesQuantity=?, monthSalesTotalPrice=? WHERE id=?", (str(name_entry_text.get()), str(id_entry_text.get()), str(quantity_sold_entry_text.get()), str(quantity_left_entry_text.get()), str(price_entry_text.get()), str(today_sales_quantity_entry_text.get()), str(today_sales_total_price_entry_text.get()), str(week_sales_quantity_entry_text.get()), str(week_sales_total_price_entry_text.get()), str(month_sales_quantity_entry_text.get()), str(month_sales_total_price_entry_text.get()), str(id_entry_text.get()))) conn.commit() Refresh() show_message('Success', 'Product updated') conn.close() except sqlite3.Error as e: show_message('Sqlite error', e) finally: Refresh() conn.close() def calculate(): price = price_entry_text.get() quantity_sold = quantity_sold_entry_text.get() quantity_left = quantity_left_entry_text.get() today_sales_quantity = today_sales_quantity_entry_text.get() week_sales_quantity = week_sales_quantity_entry_text.get() month_sales_quantity = month_sales_quantity_entry_text.get() if len(price) < 1 or len(quantity_sold) < 1 or len(quantity_left) < 1 or len(today_sales_quantity) < 1 or len(week_sales_quantity) < 1 or len(month_sales_quantity) < 1: show_message('Python error!', 'Please enter values for all fields') return try: price = int(price) quantity_sold = int(quantity_sold) quantity_left = int(quantity_left) today_sales_quantity = int(today_sales_quantity) week_sales_quantity = int(week_sales_quantity) month_sales_quantity = int(month_sales_quantity) except: show_message('Python error!', 'Please enter integer values in these fields-> Price, Today Sales(Quantity), Week Sales(Quantity), Month Sales(Quantity)') return today_sales_total_price = price * today_sales_quantity week_sales_total_price = price * week_sales_quantity month_sales_total_price = price * month_sales_quantity today_sales_total_price_entry_text.set(today_sales_total_price) week_sales_total_price_entry_text.set(week_sales_total_price) month_sales_total_price_entry_text.set(month_sales_total_price) add_button.config(state='normal') # calling this function to show stored data Refresh() # creating buttons update_button = tk.Button(text='UPDATE', width=20, height=2, command=update) delete_button = tk.Button(text='DELETE', width=20,height=2, command=delete_product) add_button = tk.Button(text='ADD', width=20, height=2, command=add_product) add_button.config(state='disabled') calculate_button = tk.Button(text='Verify And Calculate Prices', width=25, height=2, command=calculate) refresh_button = tk.Button(text='Refresh Table', width=25, height=2, command=Refresh) # placing widgets in the root window using grid name_label.grid(row=0, column=0, padx=10, pady=10, sticky='w') id_label.grid(row=1, column=0, padx=10, pady=10, sticky='w') quantity_sold_label.grid(row=2, column=0, padx=10, pady=10, sticky='w') quantity_left_label.grid(row=3, column=0, padx=10, pady=10, sticky='w') price_label.grid(row=4, column=0, padx=10, pady=10, sticky='w') today_sales_quantity_label.grid(row=5, column=0, padx=10, pady=10, sticky='w') today_sales_total_price_label.grid(row=6, column=0, padx=10, pady=10, sticky='w') week_sales_quantity_label.grid(row=7, column=0, padx=10, pady=10, sticky='w') week_sales_total_price_label.grid(row=8, column=0, padx=10, pady=10, sticky='w') month_sales_quantity_label.grid(row=9, column=0, padx=10, pady=10, sticky='w') month_sales_total_price_label.grid(row=10, column=0, padx=10, pady=10, sticky='w') name_entry.grid(row=0, column=1, padx=10, pady=10, sticky='w') id_entry.grid(row=1, column=1, padx=10, pady=10, sticky='w') quantity_sold_entry.grid(row=2, column=1, padx=10, pady=10, sticky='w') quantity_left_entry.grid(row=3, column=1, padx=10, pady=10, sticky='w') price_entry.grid(row=4, column=1, padx=10, pady=10, sticky='w') today_sales_quantity_entry.grid(row=5, column=1, padx=10, pady=10, sticky='w') today_sales_total_price_entry.grid(row=6, column=1, padx=10, pady=10, sticky='w') today_sales_total_price_entry.config(state='disabled') week_sales_quantity_entry.grid(row=7, column=1, padx=10, pady=10, sticky='w') week_sales_total_price_entry.grid(row=8, column=1, padx=10, pady=10, sticky='w') week_sales_total_price_entry.config(state='disabled') month_sales_quantity_entry.grid(row=9, column=1, padx=10, pady=10, sticky='w') month_sales_total_price_entry.grid(row=10, column=1, padx=10, pady=10, sticky='w') month_sales_total_price_entry.config(state='disabled') update_button.grid(row=3, column=2, rowspan=2, padx=15) delete_button.grid(row=6, column=2, rowspan=2, padx=15) calculate_button.grid(row=11, column=0, columnspan=2) add_button.grid(row=11, column=2) refresh_button.grid(row=11, column=3) pdt_name.grid(row=13, column=0) pdt_id.grid(row=13, column=1) pdt_price.grid(row=13, column=2) pdt_sales_quantity.grid(row=13, column=3) root_window.mainloop()
Output for Sales Management System Project in Python
Image output:
Video output:
Conclusion
We hope you enjoyed our Sales Management System Project in Python. We have added many features and already mentioned most of the features above but, we encourage you to add more features(like a search option) to make this Sales Management System Project in Python more robust and scalable in real-time. Wish you all the best.
Thank you for visiting our website.
Also Read:
- Create your own ChatGPT with Python
- SQLite | CRUD Operations in Python
- Event Management System Project in Python
- Ticket Booking and Management in Python
- Hostel Management System Project in Python
- Sales Management System Project in Python
- Bank Management System Project in C++
- Python Download File from URL | 4 Methods
- Python Programming Examples | Fundamental Programs in Python
- Spell Checker in Python
- Portfolio Management System in Python
- Stickman Game in Python
- Contact Book project in Python
- Loan Management System Project in Python
- Cab Booking System in Python
- Brick Breaker Game in Python
- Tank game in Python
- GUI Piano in Python
- Ludo Game in Python
- Rock Paper Scissors Game in Python
- Snake and Ladder Game in Python
- Puzzle Game in Python
- Medical Store Management System Project in Python
- Creating Dino Game in Python
- Tic Tac Toe Game in Python
- Test Typing Speed using Python App
- Scientific Calculator in Python
- GUI To-Do List App in Python Tkinter
- Scientific Calculator in Python using Tkinter
- GUI Chat Application in Python Tkinter