7. Add Orders
Objective: Add functionality to add orders.
Content:
Creating an add order button.
Writing the add_order function.
Validating input and updating the order list.
7.2. Importing messagebox
from tkinter import messagebox
7.3. Adding an Orders List
# Orders tracking list
orders = []
7.4. Writing the add_order Function
def add_order():
"""Validates input and adds the current selection to the order list."""
customer = customer_entry.get()
pizza = pizza_var.get()
size = size_var.get()
quantity = quantity_var.get()
if not customer:
messagebox.showerror("Input Error", "Please enter the customer name.")
customer_entry.config(bg="pink")
else:
customer_entry.config(bg="white")
orders.append((customer, pizza, size, quantity))
quantity_var.set(1) # Reset quantity to default
add_order: Function to add an order to the list.customer = customer_entry.get(): Retrieves the customer name from the entry widget.pizza = pizza_var.get(): Retrieves the selected pizza type.size = size_var.get(): Retrieves the selected pizza size.quantity = quantity_var.get(): Retrieves the selected quantity string as an integer.messagebox.showerror("Input Error", "Please enter the customer name."): Displays an error message if the customer name is not entered.orders.append((customer, pizza, size, quantity)): Adds the order to the list of orders.quantity_var.set("0"): Resets the quantity to 0.