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

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 Design a Location Tracking Module for Desktop Business Systems Using Python?

This tutorial will show you how to create an interactive map application that allows users to input geographic coordinates and visualize locations on an interactive map using Python's Tkinter GUI framework enhanced with TTKBootstrap styling and the TkinterMapView widget.  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 ttkbootstrap tkintermapview As usual, we need to import the relevant module and set the root values from tkinter import * import ttkbootstrap as tb import tkintermapview from ttkbootstrap.dialogs import Messagebox root = tb.Window(themename='darkly') root.title('Find My Map') root.geometry("1200x1200") I would like to divide it into three sections.  a) Input Panel Layout,  The headers are mainly a label...

How to Create Flask Forms with CKEditor and Flask-WTF?

In this tutorial, we will be integrating Flask-WTF and Flask-CKEditor into your Flask application! You'll learn how to set up the editor, securely handle formatted HTML content, and create a seamless user experience that enhances any project that requires user-generated content. Let's get started! Prerequisite: This tutorial is part of the Flask CKEditor Project Series. 📚 View the Complete Flask CKEditor Series                                                                                                                                                  ➡ Next Part Preliminary Before I begin, it is recommended to activate the v...

How to Store Application Data with SQLite in Python?

  In the previous tutorial, I used TinyDB as our storage solution to keep application data in a simple JSON-based format. While TinyDB is lightweight and easy to use, many web applications require a more structured and scalable database system. In this tutorial, we will switch to SQLite , a powerful relational database that integrates well with Python and web frameworks. By using SQLite, you will learn how to store, manage, and query data in a more structured way for real-world applications. Prerequisite: This tutorial is part of the Flask CKEditor Project Series. 📚 View the Complete Flask CKEditor Series ⬅ Previous Part                                                                                                         ...