$ show ragardner/tksheet
tksheet is a pure Python Tkinter widget library that provides a full-featured, interactive spreadsheet-like table and treeview component for embedding in desktop applications. It renders only visible cells using Tkinter canvases, supporting cell editing, dropdowns, checkboxes, progress bars, notes/tooltips, find/replace, sorting, undo/redo, clipboard operations, and extensive theming. The architecture is modular, with separate classes for the main table, column headers, row index, text editor, and dropdown windows, all orchestrated by a central `Sheet` class that exposes a rich API for data manipulation and event handling. The library demonstrates strong software craftsmanship through its use of reusable patterns such as `Span` objects for addressing cell ranges with method chaining, `DotDict` for attribute-accessible configuration dictionaries, and a consistent `EventDataDict` structure for undo/redo and event propagation. It also includes self-contained utility modules for data formatting (`Formatter` class) and sorting (natural, version, and fast sort keys) that could be extracted and reused independently. Development of tksheet has officially ceased except for bug fixes and behavioral issues, as stated in the README. The codebase is mature and stable, with extensive documentation and a changelog spanning multiple major versions. While the library is tightly coupled to Tkinter and has some code duplication across similar components (e.g., column headers and row index), it remains a high-quality, production-ready widget for any Python GUI application requiring tabular data interaction.
The LLM identified 3 files worth highlighting for reuse:
Contains `Span`, `DotDict`, `EventDataDict`, `Selected`, `Highlight`, and `TextEditorStorage` classes. `Span` provides a chainable API for addressing cell ranges (rows, columns, arbitrary rectangles) with methods like `.format()`, `.highlight()`, `.dropdown()`, `.checkbox()`, and `.readonly()`. `DotDict` is a simple attribute-accessible dictionary used throughout the library for configuration and event data. `EventDataDict` standardizes event payloads for undo/redo and custom bindings. These components are self-contained, well-typed, and could be extracted into a separate utility library for any Python project needing range-based data addressing or event snapshots.
Implements a generic `Formatter` class and helper functions (`formatter()`, `format_data()`) for validating, converting, and displaying cell values. Supports built-in formatters for integers, floats, percentages, booleans, and custom formatters via `format_function`, `to_str_function`, `pre/post_format_function`, and `clipboard_function`. The pattern is cleanly separated from the GUI logic and can be reused in any Python application requiring type-safe data formatting and validation, such as data entry forms or CSV exporters.
Provides multiple sort key functions (`natural_sort_key`, `version_sort_key`, `fast_sort_key`) that handle mixed Python types (None, bool, numeric, datetime, file-path strings) in a robust manner. These functions are self-contained, have no dependencies on the rest of tksheet, and can be directly imported and used in any Python project for sorting lists of heterogeneous data. The implementation demonstrates careful handling of edge cases and is a good example of reusable utility code.