Write a python pos software with all function in customtkinter
- User
Write a python pos software with all function in customtkinter
- Assistant
Write a python pos software with all function in customtkinter
Creating a complete Point of Sale (POS) system is a comprehensive task. Below is a simplified version of a POS application using customtkinter. This example includes basic functionalities such as:
For a more robust application, consider adding features like user authentication, inventory management, reporting, and data persistence using databases.
pip install customtkinterFor simplicity, we'll keep everything in a single script. In a production environment, you should organize your code into modules and use a database for data storage.
import customtkinter as ctk
from tkinter import messagebox
from functools import partial
# Initialize CustomTkinter appearance
ctk.set_appearance_mode("System") # Modes: "System" (default), "Dark", "Light"
ctk.set_default_color_theme("blue") # Themes: "blue" (default), "green", "dark-blue"
# Sample product data
PRODUCTS = [
{"id": 1, "name": "Apple", "price": 0.5},
{"id": 2, "name": "Banana", "price": 0.3},
{"id": 3, "name": "Orange", "price": 0.7},
{"id": 4, "name": "Milk", "price": 1.5},
{"id": 5, "name": "Bread", "price": 2.0},
]
class POSApp(ctk.CTk):
def __init__(self):
super().__init__()
self.title("CustomTkinter POS System")
self.geometry("800x600")
# Initialize cart as a dictionary {product_id: quantity}
self.cart = {}
# Setup UI
self.create_widgets()
def create_widgets(self):
# Frames
self.product_frame = ctk.CTkFrame(self, width=400, corner_radius=10)
self.product_frame.grid(row=0, column=0, padx=20, pady=20, sticky="nsew")
self.cart_frame = ctk.CTkFrame(self, width=400, corner_radius=10)
self.cart_frame.grid(row=0, column=1, padx=20, pady=20, sticky="nsew")
# Configure grid weights
self.grid_columnconfigure(0, weight=1)
self.grid_columnconfigure(1, weight=1)
self.grid_rowconfigure(0, weight=1)
# Product List
product_label = ctk.CTkLabel(self.product_frame, text="Products", font=ctk.CTkFont(size=20, weight="bold"))
product_label.pack(pady=10)
self.product_listbox = ctk.CTkScrollableFrame(self.product_frame)
self.product_listbox.pack(fill="both", expand=True, padx=10, pady=10)
for product in PRODUCTS:
frame = ctk.CTkFrame(self.product_listbox, corner_radius=5)
frame.pack(fill="x", pady=5)
name_label = ctk.CTkLabel(frame, text=product["name"], font=ctk.CTkFont(size=16))
name_label.pack(side="left", padx=10)
price_label = ctk.CTkLabel(frame, text=f"${product['price']:.2f}", font=ctk.CTkFont(size=16))
price_label.pack(side="left", padx=10)
add_button = ctk.CTkButton(frame, text="Add", width=50,
command=partial(self.add_to_cart, product["id"]))
add_button.pack(side="right", padx=10)
# Cart List
cart_label = ctk.CTkLabel(self.cart_frame, text="Cart", font=ctk.CTkFont(size=20, weight="bold"))
cart_label.pack(pady=10)
self.cart_listbox = ctk.CTkScrollableFrame(self.cart_frame)
self.cart_listbox.pack(fill="both", expand=True, padx=10, pady=10)
# Total and Payment
self.total_var = ctk.StringVar(value="Total: $0.00")
total_label = ctk.CTkLabel(self.cart_frame, textvariable=self.total_var, font=ctk.CTkFont(size=18))
total_label.pack(pady=10)
pay_button = ctk.CTkButton(self.cart_frame, text="Process Payment", command=self.process_payment)
pay_button.pack(pady=10)
self.update_cart_ui()
def add_to_cart(self, product_id):
if product_id in self.cart:
self.cart[product_id] += 1
else:
self.cart[product_id] = 1
self.update_cart_ui()
def remove_from_cart(self, product_id):
if product_id in self.cart:
self.cart[product_id] -= 1
if self.cart[product_id] <= 0:
del self.cart[product_id]
self.update_cart_ui()
def update_cart_ui(self):
# Clear current cart list
for widget in self.cart_listbox.winfo_children():
widget.destroy()
total = 0.0
for product_id, quantity in self.cart.items():
product = next((p for p in PRODUCTS if p["id"] == product_id), None)
if product:
frame = ctk.CTkFrame(self.cart_listbox, corner_radius=5)
frame.pack(fill="x", pady=5)
name_label = ctk.CTkLabel(frame, text=product["name"], font=ctk.CTkFont(size=16))
name_label.pack(side="left", padx=10)
quantity_label = ctk.CTkLabel(frame, text=f"Qty: {quantity}", font=ctk.CTkFont(size=16))
quantity_label.pack(side="left", padx=10)
price = product["price"] * quantity
price_label = ctk.CTkLabel(frame, text=f"${price:.2f}", font=ctk.CTkFont(size=16))
price_label.pack(side="left", padx=10)
remove_button = ctk.CTkButton(frame, text="Remove", width=70,
command=partial(self.remove_from_cart, product_id))
remove_button.pack(side="right", padx=10)
total += price
self.total_var.set(f"Total: ${total:.2f}")
def process_payment(self):
if not self.cart:
messagebox.showwarning("Empty Cart", "Your cart is empty!")
return
total = sum(next((p["price"] for p in PRODUCTS if p["id"] == pid), 0) * qty
for pid, qty in self.cart.items())
# Here you can add payment processing logic
# For simplicity, we'll just show a confirmation dialog
confirm = messagebox.askyesno("Process Payment", f"Total amount: ${total:.2f}\nDo you want to proceed?")
if confirm:
messagebox.showinfo("Payment Successful", "Payment has been processed successfully!")
self.cart.clear()
self.update_cart_ui()
if __name__ == "__main__":
app = POSApp()
app.mainloop()
Imports and Setup:
customtkinter is used for creating modern-looking GUI components.messagebox is utilized for dialog boxes.functools.partial helps in passing arguments to callback functions.Sample Product Data:
POSApp Class:
ctk.CTk, the main window class.UI Components:
Cart Management:
Payment Processing:
To make this POS system more robust, consider implementing the following features:
Data Persistence:
User Authentication:
Inventory Management:
Reporting:
Receipt Generation:
Error Handling:
UI Enhancements:
Payment Integration:
This example provides a foundational structure for a POS system using customtkinter. Depending on your requirements, you can expand and customize this application to include more advanced features and integrate it with external systems and databases.
Not yet included in a published release.