Restaurant Management System in Python with Tkinter

Rashmi Mishra

 


Restaurant Management System in Python with Tkinter (Source Code)

creating a restaurant management system using Python and Tkinter, a popular GUI toolkit.



I. Introduction


Welcome to this article where we will explore the process of building a restaurant management system using  Python and Tkinter. A restaurant management system is a valuable tool that streamlines various tasks and processes within a restaurant, such as managing menu items, processing orders, handling payments, and generating reports. By developing a custom system with  Python and Tkinter, we can create a tailored solution that meets the specific needs of a restaurant.


II. Understanding the Restaurant Management System

A restaurant management system is a software application designed to assist restaurant owners and managers in efficiently managing their operations. It automates several processes, including order management, inventory tracking, employee management, table reservations, and customer relationship management. With a well-designed restaurant management system, restaurant owners can enhance productivity, reduce errors, and provide better customer service.



III. Benefits of Building a Restaurant Management System

Building a restaurant management system from scratch offers several advantages over using off-the-shelf solutions. Here are a few key benefits:


Customization: By developing your own system, you can tailor it to fit the specific requirements of your restaurant, ensuring that it aligns perfectly with your workflow and business processes.

Cost-effectiveness: While commercial restaurant management systems can be expensive, building your own with  Python and Tkinter can significantly reduce costs, as open-source tools and libraries are freely available.

Scalability: As your restaurant grows, you can easily scale and expand your custom system to accommodate new features and functionality.

Learning opportunity: Developing a restaurant management system is an excellent learning experience, allowing you to enhance your  Python programming skills and gain a deeper understanding of software development.

IV. Choosing Python and Tkinter for Development


 Python is a powerful and versatile programming language known for its simplicity and readability. It offers a wide range of libraries and frameworks that simplify the development process. Tkinter, the standard  Python interface to the Tk GUI toolkit, provides a simple and intuitive way to create graphical user interfaces (GUIs).


By combining Python and Tkinter, we can create a user-friendly and responsive restaurant management system that runs seamlessly on various platforms.


V. Setting up the Development Environment

Before we dive into building the restaurant management system, let's set up our development environment. Follow these steps:


Install Python: Download and install the latest version of  Python from the official website (python.org). Choose the appropriate installer based on your operating system.

Install Tkinter: Tkinter comes pre-installed with Python, so you don't need to install it separately.

IDE Selection: Choose an integrated development environment (IDE) for  Python development. Popular choices include PyCharm, Visual Studio Code, and IDLE (included with Python).

VI. Full Source Code

import tkinter as tk

from tkinter import messagebox


class RestaurantManagementSystem:

    def __init__(self, root):

        self.root = root

        self.root.title("Restaurant Management System")


        self.customer_name = tk.StringVar()

        self.customer_contact = tk.StringVar()


        self.items = {

            "Burger": 100,

            "Pizza": 200,

            "Pasta": 150,

            "Sandwich": 80,

            "Salad": 90

        }


        self.orders = {}


        self.gst_percentage = 18


        self.create_gui()


    def create_gui(self):

        details_frame = tk.LabelFrame(self.root, text="Customer Details")

        details_frame.pack(fill="x", padx=10, pady=10)


        name_label = tk.Label(details_frame, text="Name:")

        name_label.grid(row=0, column=0, padx=5, pady=5, sticky="e")

        name_entry = tk.Entry(details_frame, textvariable=self.customer_name)

        name_entry.grid(row=0, column=1, padx=5, pady=5, sticky="w")


        contact_label = tk.Label(details_frame, text="Contact:")

        contact_label.grid(row=1, column=0, padx=5, pady=5, sticky="e")

        contact_entry = tk.Entry(details_frame, textvariable=self.customer_contact)

        contact_entry.grid(row=1, column=1, padx=5, pady=5, sticky="w")

        contact_entry.configure(validate="key")

        contact_entry.configure(validatecommand=(contact_entry.register(self.validate_contact), "%P"))


        menu_frame = tk.LabelFrame(self.root, text="Menu")

        menu_frame.pack(fill="both", expand=True, padx=10, pady=10)


        item_header = tk.Label(menu_frame, text="Items")

        item_header.grid(row=0, column=0, padx=5, pady=5, sticky="w")

        quantity_header = tk.Label(menu_frame, text="Quantity")

        quantity_header.grid(row=0, column=1, padx=5, pady=5, sticky="w")


        row = 1

        for item, price in self.items.items():

            item_var = tk.IntVar()

            item_label = tk.Label(menu_frame, text=f"{item} - {self.convert_to_inr(price)}")

            item_label.grid(row=row, column=0, padx=5, pady=5, sticky="w")


            quantity_entry = tk.Entry(menu_frame, width=5)

            quantity_entry.grid(row=row, column=1, padx=5, pady=5, sticky="w")


            self.orders[item] = {"var": item_var, "quantity": quantity_entry}


            row += 1


        buttons_frame = tk.Frame(self.root)

        buttons_frame.pack(fill="x", padx=10, pady=10)


        print_bill_button = tk.Button(buttons_frame, text="Print Bill", command=self.show_bill_popup)

        print_bill_button.pack(side="left", padx=5)


        past_record_button = tk.Button(buttons_frame, text="Past Records", command=self.past_records)

        past_record_button.pack(side="left", padx=5)


        clear_selection_button = tk.Button(buttons_frame, text="Clear Selection", command=self.clear_selection)

        clear_selection_button.pack(side="left", padx=5)


        self.sample_bill_text = tk.Text(self.root, height=10)

        self.sample_bill_text.pack(fill="x", padx=10, pady=10)


        # Update sample bill when quantity or item is selected

        for item, info in self.orders.items():

            info["quantity"].bind("<FocusOut>", lambda event, item=item: self.update_sample_bill(item))

            info["quantity"].bind("<Return>", lambda event, item=item: self.update_sample_bill(item))

            info["quantity"].bind("<KeyRelease>", lambda event, item=item: self.update_sample_bill(item))

            info["var"].trace("w", lambda *args, item=item: self.update_sample_bill(item))


    def show_bill_popup(self):

        # Check if customer name is provided

        if not self.customer_name.get().strip():

            messagebox.showwarning("Warning", "Please enter customer name.")

            return


        selected_items = []

        total_price = 0


        for item, info in self.orders.items():

            quantity = info["quantity"].get()

            if quantity:

                selected_items.append((item, int(quantity)))

                total_price += self.items[item] * int(quantity)


        if not selected_items:

            messagebox.showwarning("Warning", "Please select at least one item.")

            return


        gst_amount = (total_price * self.gst_percentage) / 100


        bill = f"Customer Name: {self.customer_name.get()}\n"

        bill += f"Customer Contact: {self.customer_contact.get()}\n\n"

        bill += "Selected Items:\n"

        for item, quantity in selected_items:

            bill += f"{item} x {quantity} - {self.convert_to_inr(self.items[item] * quantity)}\n"

        bill += f"\nTotal Price: {self.convert_to_inr(total_price)}\n"

        bill += f"GST ({self.gst_percentage}%): {self.convert_to_inr(gst_amount)}\n"

        bill += f"Grand Total: {self.convert_to_inr(total_price + gst_amount)}"


        messagebox.showinfo("Bill", bill)


    def past_records(self):

        messagebox.showinfo("Past Records", "This feature is not implemented yet.")


    def clear_selection(self):

        for item, info in self.orders.items():

            info["var"].set(0)

            info["quantity"].delete(0, tk.END)


    def update_sample_bill(self, item):

        selected_items = []

        total_price = 0


        for item, info in self.orders.items():

            quantity = info["quantity"].get()

            if quantity:

                selected_items.append((item, int(quantity)))

                total_price += self.items[item] * int(quantity)


        gst_amount = (total_price * self.gst_percentage) / 100


        bill = f"Customer Name: {self.customer_name.get()}\n"

        bill += f"Customer Contact: {self.customer_contact.get()}\n\n"

        bill += "Selected Items:\n"

        for item, quantity in selected_items:

            bill += f"{item} x {quantity} - {self.convert_to_inr(self.items[item] * quantity)}\n"

        bill += f"\nTotal Price: {self.convert_to_inr(total_price)}\n"

        bill += f"GST ({self.gst_percentage}%): {self.convert_to_inr(gst_amount)}\n"

        bill += f"Grand Total: {self.convert_to_inr(total_price + gst_amount)}"


        self.sample_bill_text.delete("1.0", tk.END)  # Clear previous contents

        self.sample_bill_text.insert(tk.END, bill)


    def validate_contact(self, value):

        return value.isdigit() or value == ""


    @staticmethod

    def convert_to_inr(amount):

        return "₹" + str(amount)


root = tk.Tk()

restaurant_system = RestaurantManagementSystem(root)

root.mainloop()Copy

VII. Explanation of Source Code


Let's go through the code step by step:


1. The code begins by importing the necessary modules: tkinter and messagebox.


2. Next, a class named RestaurantManagementSystem is defined. It represents the main application and contains methods and attributes to manage the restaurant system.


3. In the __init__ method, the root window is initialized and given a title. The root parameter represents the main window of the application.


4. Several instance variables are defined:


customer_name and customer_contact are instances of StringVar() from Tkinter. They are used to store the customer's name and contact information.

items is a dictionary that stores the available items in the restaurant as keys and their respective prices as values.

orders is an empty dictionary that will be used to store the selected items and their quantities.

gst_percentage represents the percentage of GST (Goods and Services Tax) to be applied to the total bill.

5. The create_gui method is defined to build the graphical user interface of the application. It creates various labels, entry fields, buttons, and a text box using the Tkinter widgets.



6. The show_bill_popup method is called when the "Print Bill" button is clicked. It retrieves the customer's name and contact information. Then, it iterates over the selected items and calculates the total price based on the quantity and item prices. The bill information is displayed in a message box.


7. The past_records method is called when the "Past Records" button is clicked. However, it currently displays a message box stating that this feature is not implemented yet.


8. The clear_selection method is called when the "Clear Selection" button is clicked. It clears the selected items by setting their variables to 0 and deleting the content of the quantity entry fields.


9. The update_sample_bill method is called whenever the quantity or item selection is changed. It calculates the total price, generates the bill information, and updates the content of the sample bill text box accordingly.



10. The validate_contact method is a helper function that is used to validate the customer's contact information. It ensures that the value entered is either empty or consists of digits only.


11. The convert_to_inr method is a helper function that takes an amount and returns it as a formatted string in Indian Rupees (₹).


12. Finally, an instance of the RestaurantManagementSystem class is created, passing the root window as an argument. The Tkinter event loop is started with the mainloop() method, which allows the application to respond to user interactions and events.


Overall, this code creates a simple restaurant management system with a graphical user interface, allowing users to enter customer details, select items from a menu, calculate the bill, and display it in a message box.


VIII. Conclusion

In conclusion, building a restaurant management system in  Python with Tkinter empowers restaurant owners and managers to streamline operations, improve customer service, and drive business growth. By leveraging the power of these technologies, you have the ability to create a customized and scalable solution that revolutionizes the way your restaurant operates.