Menu

ExtMultiListbox Log in to Edit

klappnase

ExtMultiListbox

A flexible multi column listbox widget for Tkinter.
The ExtMultiListbox class is an extended version of the MultiListbox
class, with convenience methods that support icons, checkboxes and
user-editable text. For methods not described here please refer to the
MultiListbox and Treectrl class references.
Based on the Treectrl widget, the ExtMultiListbox offers the following
additional configuration options:

checkboxcmd -       an optional command that will be invoked each
                    time a listbox item's checkbox is clicked or
                    the checkbox_set() or checkbox_toggle() method is
                    called; three arguments are passed to this command:
                    the listbox index and column of the checkbox and
                    the new state (True (checked) or False (unchecked))
                    of the checkbox. The default is None.
checkboxicons -     may be a two-tuple of the form (on_icon, off_icon)
                    or None. If set to None (the default) the default
                    built-in images will be used to display checkboxes.
                    Otherwise the given on_icon and off_icon will be
                    used. on_icon and off_icon must either be of type
                    PhotoImage or a string describing a valid image
                    name. Please note that if the icons are to be
                    changed on the fly in very large lists this can be
                    rather slow. For switching the checkbox icons in
                    large lists, custom images should be applied at
                    widget initialisation and if desired later these
                    image's file or data options reconfigured.
columns -           a sequence of strings that defines the number of
                    columns of the widget. The strings will be used in
                    the columnheader lines (default: ('',)). On widget
                    initialisation these columns will be created
                    automatically. After initialisation this option
                    can be used to change the column header text for
                    each column. It is not possible however to change
                    the number of existing columns with this option.
                    To create or delete columns, use the
                    column_create() and column_delete() methods instead.
command -           an optional command that will be executed when the
                    user double-clicks into the listbox or presses the
                    Return key. The listbox index of the item that was
                    clicked on resp. of the currently active item is
                    passed as argument to the callback; if there is no
                    item at the event coordinates resp. no active item
                    exists, this index will be -1 (default: None).
outlinecolor -      color to use for the outline of the listbox cells
                    (default: "gray50").
outlinewidth -      width of the outline of the listbox cells
                    (default: 0).
selectcmd -         an optional callback that will be executed when the
                    selection of the listbox changes. Three arguments
                    will be passed to this command: a tuple containing
                    the listbox indices of newly selected items, a
                    tuple containing the indices of newly deselected
                    items and the number of selected items
                    (default: None).
selectbackground -  the background color to use for the selection
                    rectangle (default: #00008B).
selectforeground -  the foreground color to use for selected text
                    (default: white).
validatecmd -       optional command that will be called to validate
                    user input when the widget is in "edit" state.
                    Three arguments are passed to this command:
                    the listbox index and column of the cell that
                    is being edited and the new text after the edit.
                    Must return True if the new text shall be accepted,
                    False otherwise. Default: None

The widget has three pre-defined styles, which can be accessed with the
style() method by their alias-names "text", "icons" and "both".
By default, the widget uses the style "both" for all columns, which will
display both "icon" and "text" elements; with the widget's style() method
both the built-in styles and newly created user-defined styles can be
accessed and configured; the columnstyle_*() methods allow to apply other
built-in styles or new user-defined styles per column.
The default styles define three elements, with the alias-names "text",
"icon" and "select" (which describes attributes of the selection rectangle);
these may be accessed and configured with the element() method.

Two additional states are pre-defined for the widget: "checked" and
"textedit". The "checked" state is set as itemstate_percolumn state when a
checkbox is switched to the "on" state. The "textedit" state is handled by
the built-in handlers for <textedit-*> events after textedit_enable() has
been called.</textedit-*>

For convenience in the methods defined here the Treectrl items are not
addressed by Treectrl item descriptors but by listbox indices.
Conversion between listbox indices and treectrl item descriptors can be
done with the item() and index() widget methods. Besides this, most common
operations can be done with methods identical or very similar to those of a
tkinter.Listbox, with the exception of the selection_() methods, where the
treectrl methods are kept intact; for tkinter.Listbox alike methods, use
select_
().

Column handling
For convenience in the methods defined here the widget columns are not
addressed by Treectrl column identifiers but by column indices, with the
leftmost column being at index 0. The rightmost column may also be
addressed by the special index "end" (similar to item indices in a
tkinter.Listbox). The conversion between column index and column identifier
can be done with the column() and columnindex() methods.
This applies to the following methods defined here:
checkbox_get(), checkbox_set(), checkbox_toggle(), column_create(),
column_delete(), column_configure(), column_cget(), column_move(),
column_set_editable(), columnstyle_get(), columnstyle_set(),
columnstyle_update(), bbox(), see() and sort().
Other methods, which have been inherited from Treectrl still use Treectrl
column identifiers though.
Columns can be dynamically created or removed with the column_create() and
column_delete() commands. It should be noted however that column_create()
can be slow when applied to very large lists. In most situations it should
therefore be preferred to create all possibly needed columns during widget
initialisation and hide or show columns as desired by changing the
respective column's "visible" option.


Related

Wiki: CustomClasses

Discussion

  • klappnase

    klappnase - 2022-12-18

    Version 0.1
    Edit: attached pydoc html manual

     

    Last edit: klappnase 2022-12-18
  • klappnase

    klappnase - 2023-01-05

    Version 0.2
    This version now includes a ScrolledExtMultiListbox class.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.