Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk5 min

How to Create a Searchable Tkinter Panel in Python

Create a searchable Tkinter table with a labeled entry, a Treeview, a scrollbar, and a StringVar callback that filters records as you type.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build a live-search panel by combining a labeled ttk.Entry, a ttk.Treeview, and a scrollbar inside a ttk.Frame. Connect the entry to a StringVar, keep the original records in Python, and redraw the visible rows whenever the query changes. The example below searches two text fields using case-insensitive substring matching; clearing the query restores every record.

What the panel does—and what it does not do

Tkinter is Python’s standard interface to the Tcl/Tk GUI toolkit, as the Python documentation explains. A searchable panel is not a special Tkinter search widget. It is a small composition of themed widgets: an entry for the query, a Treeview for tabular results, and a scrollbar for navigating them.

The themed Tk widgets reference documents ttk.Entry and ttk.Treeview. A Treeview can display data columns as well as hierarchical items; this example uses it as a flat table. Filtering is application logic: the program compares the query with source records and repopulates the widget with matches.

Complete working example

Save this as search_panel.py and run it with Python. The search covers only each record’s name and category fields. It trims whitespace at either end of the query and uses casefold() for case-insensitive substring matching.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import tkinter as tk
from tkinter import ttk

records = [
    {"name": "Wireless Keyboard", "category": "Accessories", "price": "$39"},
    {"name": "USB-C Hub", "category": "Accessories", "price": "$52"},
    {"name": "Desk Lamp", "category": "Office", "price": "$28"},
    {"name": "Notebook Stand", "category": "Office", "price": "$44"},
    {"name": "Portable SSD", "category": "Storage", "price": "$89"},
]

root = tk.Tk()
root.title("Searchable inventory")
root.minsize(520, 300)

panel = ttk.Frame(root, padding=12)
panel.grid(row=0, column=0, sticky="nsew")
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
panel.columnconfigure(0, weight=1)
panel.rowconfigure(2, weight=1)

ttk.Label(panel, text="Search name or category:").grid(
    row=0, column=0, sticky="w", pady=(0, 4)
)
query = tk.StringVar()
search_entry = ttk.Entry(panel, textvariable=query)
search_entry.grid(row=1, column=0, sticky="ew", pady=(0, 10))

columns = ("name", "category", "price")
tree = ttk.Treeview(panel, columns=columns, show="headings", height=8)
tree.heading("name", text="Name")
tree.heading("category", text="Category")
tree.heading("price", text="Price")
tree.column("name", width=210, anchor="w")
tree.column("category", width=140, anchor="w")
tree.column("price", width=90, anchor="e")

y_scrollbar = ttk.Scrollbar(panel, orient="vertical", command=tree.yview)
tree.configure(yscrollcommand=y_scrollbar.set)
tree.grid(row=2, column=0, sticky="nsew")
y_scrollbar.grid(row=2, column=1, sticky="ns")

status = ttk.Label(panel, text="")
status.grid(row=3, column=0, columnspan=2, sticky="w", pady=(8, 0))

def render(rows):
    # Remove displayed rows, not the original records.
    tree.delete(*tree.get_children())
    for row in rows:
        tree.insert("", "end", values=(row["name"], row["category"], row["price"]))
    status.config(text="" if rows else "No matching records.")

def filter_records(*_):
    needle = query.get().strip().casefold()
    if not needle:
        matches = records
    else:
        matches = [
            row for row in records
            if needle in row["name"].casefold()
            or needle in row["category"].casefold()
        ]
    render(matches)

query.trace_add("write", filter_records)
render(records)
search_entry.focus_set()
root.mainloop()

How the pieces work together

Keep source data separate from displayed rows

records is the source collection. The Treeview contains only the rows currently shown. The render() function deletes those displayed items and inserts the supplied records again. Since filtering never deletes from records, an empty search can reliably restore the full list.

Connect the entry to the filter callback

The entry’s textvariable is the StringVar named query. Registering filter_records with query.trace_add("write", ...) means typing, deleting, or pasting text triggers the callback. Tkinter passes trace details to the callback, so *_ accepts and ignores them.

Configure the table and scrollbar

columns defines the data fields shown in the Treeview, while heading() supplies visible column labels. The scrollbar’s command calls tree.yview, and the Treeview’s yscrollcommand calls the scrollbar’s set method. The grid weights let the table grow with the window.

Choose the search behavior deliberately

  • Search fields: This example searches name and category, not price. Adjust the predicate if other fields should be searchable, and make the label describe those fields.
  • Match rule: needle in field.casefold() finds a substring without case sensitivity. Prefix, exact, token-based, and regular-expression searches behave differently; use them only when they suit the interface and explain them to users.
  • Empty query: The function renders the original collection again when the trimmed query is empty.
  • No matches: The status label displays “No matching records.” when filtering returns no rows.
  • Record types: The sample assumes the named fields exist and contain strings. If input data can omit fields or contain values such as None, validate or convert those values before calling casefold().

Adapt the panel to your data and scale

For different columns or hierarchical data

Change the Treeview column names, headings, and values passed to insert() to match your records. A Treeview also supports parent-child items. For nested data, decide whether a match should include only a matching item or also its ancestors; the flat-list filter above does not make that decision for you.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For larger or remote data sources

This example filters a small in-memory list by checking records after each edit. It makes no performance guarantee for a particular dataset size. For expensive filtering, debounce the callback so it runs after a brief pause in typing; for data stored remotely or in a database, query that source using an appropriate strategy rather than loading and scanning everything on every keystroke.

For selection and keyboard use

When the Treeview is refreshed, its old displayed items are deleted, so a selected item may disappear. If selection should survive filtering, retain a stable record identifier and restore selection when that record remains among the matches. The visible label gives the entry context, and focus_set() places the initial keyboard focus in it; ordinary entry editing remains available.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check your Tkinter installation and version

Run python -m tkinter in a terminal to check whether Tkinter launches and inspect the Tcl/Tk version available to that Python installation. The Python 3.14 documentation says official Python binary releases bundle threaded Tcl/Tk 8.6, but another build or environment may differ; Tkinter support depends on the Tcl/Tk installation. The standard Treeview APIs used above are documented in Python 3.14’s stable reference.

A newer Treeview.search() method appears in Python 3.16.0a0 development documentation and requires Tk 9.1 or newer. Its availability is version-sensitive, so it is not a general replacement for the filtering pattern above on common installations. Check your actual Python and Tk versions before relying on it.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Further learning

For a broader Tkinter reference, TkDocs describes Mark Roseman’s Modern Tkinter for Busy Python Developers, fourth edition, as a 2025 update for Python 3.14 available in paperback and Kindle formats. It covers more than searchable panels, so it is optional reading rather than a requirement for this example.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.