Skip to main content

Self-filtering Listbox with text entry for Tkinter

Project description

tkFilterList is a combination of the Tkinter Listbox and Entry widgets that updates to display matching items as you type.


tkFilterList consists of a single module, tkfilterlist (note the module name is lowercase), which exports a single class, FilterList.

A brief example program:

#!/usr/bin/env python3

from tkinter import *
from tkinter.messagebox import showinfo
from tkfilterlist import FilterList
import operator

# Source items for the FilterList
# Format: display_text, symbol, operator
source = [("Addition", "+", operator.add),
          ("Subtraction", "-", operator.sub),
          ("Multiplication", "*", operator.mul),
          ("Division", "/", operator.floordiv)]

# Create a root window
root = Tk()

# Create a FilterList widget
fl = FilterList(root,
                display_rule=lambda item: item[0],
                filter_rule=lambda item, text:
fl.pack(side="top", expand=1, fill="both")

def show_result(event=None):
    a, b = 42, 7
    item = fl.selection()
    if item:
                 "{0} {1} {2} = {3}".format(a, item[1], b, item[2](a, b)),

# Show the result of the calculation on Return or double-click
fl.bind("<Return>", show_result)
fl.bind("<Double-Button-1>", show_result)

# Focus on the FilterList widget

# Start Tk's event loop

For detailed documentation, try python -m pydoc tkfilterlist.


You can customize the item display and filtering behavior by setting its display_rule and filter_rule options, respectively, to your own custom functions. This allows tkFilterList to process lists containing complex datatypes, including nested lists, tuples, and even entire classes. The functions are defined as follows:

Function Description
display_rule(item) Returns the display text for the specified item.
filter_rule(item, text) Returns True if the text argument matches the specified item, False otherwise.

The default display rule is available as FilterList.default_display_rule. It returns the string value of item, matching the behavior of a standard Listbox widget.

The default filter rule is available as FilterList.default_filter_rule. It returns True if an item starts with the specified text using a case-insensitive match.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for tkFilterList, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size tkFilterList-0.1.2.tar.gz (5.9 kB) File type Source Python version None Upload date Hashes View
Filename, size tkFilterList-0.1.2-py2.py3-none-any.whl (7.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page