Skip to main content

How to Display Inventory Transactions in a Python Table View?


The Stock Records Table provides a convenient overview of all inventory transactions stored in the system. It displays important information such as transaction type (Add or Withdraw), item category, customer details, order date, stock status, quantity, unit price, total value, and product image. Users can select a record from the table to automatically populate the dashboard form for review or updating. This feature makes it easier to track inventory movements, monitor stock levels, and manage records efficiently from a single interface.

Prerequisite:

This tutorial is part of the CustomTkinter Inventory Management System Series.

📚 View the Complete CustomTkinter Inventory Management System Series

⬅ Previous Part

Preliminary: 
Before I begin, please activate the virtual environment and install the required dependencies.
python -m venv venv
venv\Scripts\activate
pip install CTkTable ctktablerowselector==1.0.1 pillow
Then, we need to set up the file and folder structure, as below:
Everything is as before, except in this tutorial, I will add and use a table.py file and also connect the window with the table button in the app.py file.

Step 1: Set up a table window
First and foremost, let me connect the table button. So, when I click the table button, it will pop up a table window as shown below:
Since the display window logic is all in the table.py file. Therefore, to display the window, I need to connect the table window with the table button in app.py as follows:
from table import open_table

# ---------------- TABLE BUTTON ----------------
# Button used to display inventory records in table view
table_button = ctk.CTkButton(button_frame, text="Table", font=font_bold, 
                      state='disabled', command=lambda: open_table(
                          root, item_name_entry,   
                          name_entry, address_entry,     
                          email_entry, select_date_label, 
                          radio_var, quantity_entry,   
                          unit_price_entry, price_label,       
                          table_window, picture_label))    
table_button.grid(row=0, column=4, padx=10, pady=10)
While setting up the table in the table.py file, and my code is as follows:
import customtkinter as ctk
from CTkTable import CTkTable
from CTkTableRowSelector import *
from tinydb import TinyDB
from tinydb.operations import delete
from PIL import Image
import os

db = TinyDB('inventory/inventory.json')
table = None
table_window = None

def open_table(parent, item_name_entry,      
               name_entry, address_entry,        
               email_entry, select_date_label,    
               radio_var, quantity_entry,       
               unit_price_entry, price_label,          
               table_window, picture_label):       
               
    global table
    
    table_window = ctk.CTkToplevel(parent)
    table_window.geometry("1400x600")
    table_window.title('Inventory Management System')
    ctk.set_appearance_mode('dark')
    ctk.set_default_color_theme('inventory/custom_theme.json')
(Ps: the argument that passes to the function from table.py to app.py must be equal; otherwise, it will be shown as an error.)


Step 2: Configure the data from inventory.json to display in CTkTable
Once the window is ready, I can now add a 'CTktable' widget to the window and source the data from inventory.json and display it on the table as below:
My code is as below:
# Headers for the table
    headers = [
        "Type", "Item", "Name", "Address",
        "Email", "Order Date", "Stock Status",
        "Quantity", "Unit Price", "Total value",
        "Picture"
    ]
    table_data = [headers]
    
    # Fetch data from the database and 
    # prepare it for the table
    db_data = db.all()
    
    # Loop through all records retrieved from TinyDB
    for item in db_data:
        # Get the quantity value from the current record
        quantity = float(item.get("quantity", "0.00"))
        unit_price = float(item.get("unit_price", "0.00"))
        
        # Calculate the total cost
        total_cost = quantity * unit_price
        
        # Format the total cost to 2 decimal places
        formatted_total_cost = f"{total_cost:.2f}"
        
        # Add the record to the table data list
        table_data.append([
            item.get("type", ""),
            item.get("item", ""),
            item.get("name", ""),
            item.get("address", ""),
            item.get("email", ""),
            item.get("order_date", ""),
            item.get("stock_status", ""),
            item.get("quantity", ""),
            item.get("unit_price", ""),
            # calculation from above
            formatted_total_cost,
            item.get("picture", "")
        ])
    
    # destroy old table
    if table is not None:
        table.destroy()
        
    # Create the table and add it to the scrollable frame    
    scroll_frame = ctk.CTkScrollableFrame(
        table_window,
        width=1300,
        height=400
    )
    scroll_frame.pack(expand=True, fill="both", padx=20, pady=20)

    table = CTkTable(
        master=scroll_frame,
        row=len(table_data),
        column=len(headers),
        values=table_data,
        header_color="blue",
        corner_radius=10,
        justify="center",
        text_color="white"
    )
    table.pack(expand=True, fill="both", padx=20, pady=20)
    
# Refresh the table window immediately table_window.update() #### Add the selector #### row_selector = CTkTableRowSelector(table)

Final wrap-up 
In this tutorial, we created a table window using CustomTkinter to display inventory records stored in TinyDB. The table provides a convenient way to view stock transactions, select records, and load data back into the application for further processing. This feature improves data visibility and makes inventory management more efficient. To view the full code, please click here.

Published: May 2026
Last Updated: May 2026

---------------------------------------------------------------------------------------------------------------------------------------------------

🎁 Get Your FREE Flask Cheat Sheet

Join 500+ Python learners and receive this printable Flask Cheat Sheet instantly. Plus, get new Flask tutorials delivered to your inbox.

✓ Practical coding tutorials
✓ Automation tips for SMEs
✓ New project ideas and templates

-----------------------------------------------------------------------------------------------------------------------------
Need a similar system for your business? 
I build custom Flask web applications and Python automation solutions for SMEs and solopreneurs. 


-----------------------------------------------------------------------------------------------------------------------------
About the Author

Kelvin Loh is a Python developer focused on Flask, desktop applications, and business automation solutions. He shares practical tutorials and real-world coding projects to help developers and small businesses build useful applications.

Comments

Popular Posts

How to Build an Audiobook Workflow Desktop System with Python?

In this tutorial, we will build a simple audiobook player using Python and CustomTkinter. You will learn how to convert text into speech using gTTS and play it with PyGame. We will also implement play, pause, and stop controls, like those in a real audio player. By the end, you will have a clean and functional desktop audiobook app. Prerequisite: This tutorial is part of the standalone tutorial. 📚 View the standalone tutorial Preliminary   Before I begin, it is recommended to activate the virtual environment before installing the relevant dependencies. python -m venv venv venv\Scripts\activate pip install customtkinter pillow gTTS pygame CTkMessagebox pypdf Then, the following steps include setting up the file structure, app.py, and two additional folders: the uploads and media folders. The media folder contains the icons necessary to build the app; there are read, pause, and stop icons, as shown on the diagram. Step 1: Build up the app interface I have 4 sections here: the...

How to Set Up PgAdmin and Adminer Using Docker Compose?

If you are new to database management with Docker, this tutorial will guide you through setting up both PgAdmin and Adminer using Docker containers. By containerising these tools, you can quickly launch lightweight and portable database management environments without installing them directly on your operating system. This approach also makes it easier to manage configurations, updates, and multiple projects across different devices.