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.

Usage

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,
                source=source,
                display_rule=lambda item: item[0],
                filter_rule=lambda item, text:
                            item[0].lower().startswith(text.lower()))
fl.pack(side="top", expand=1, fill="both")

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

# 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
fl.focus_set()

# Start Tk's event loop
root.mainloop()

For detailed documentation, try python -m pydoc tkfilterlist.

Customization

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.

Source Distribution

tkFilterList-0.1.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

tkFilterList-0.1.2-py2.py3-none-any.whl (7.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file tkFilterList-0.1.2.tar.gz.

File metadata

  • Download URL: tkFilterList-0.1.2.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.0.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8

File hashes

Hashes for tkFilterList-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f085b690ed70d09fa082d77c7066943875ed6d6146ca59af335fa94aa9ad5efd
MD5 fca1fdffbdfc3c5ee6a348406e47d693
BLAKE2b-256 cc1ffbb842434191e44bb2765dff80114d529684a67ad067c1c5c8665e20a83b

See more details on using hashes here.

File details

Details for the file tkFilterList-0.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: tkFilterList-0.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.0.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8

File hashes

Hashes for tkFilterList-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f958c7031a420b3108998fedd052797411a2f55d38998f60f453b7c1b2b224d3
MD5 597b63c3b602489d44731920091d6070
BLAKE2b-256 b48185ab4d461d3f361615716a547468c014235059751caa48eaa4e50bda7ce5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page