pyyeti.guitools.MultiColumnListbox¶
- class pyyeti.guitools.MultiColumnListbox(title, headers, lists, topstring='Click on header to sort by that column;\nDrag boundary to change width of column')[source]¶
Use a ttk.TreeView to build a linked, multicolumn listbox.
Once a window is created, you may select a single item by either selecting a row and pressing “Done” or by double-clicking a row. Or, you may select multiple items and pressing “Done”.
You can filter the values shown by entering strings in the filter boxes above the multicolumn listbox and hitting the Return key. All values in a row must match their respective filter for the row to remain visible. A value matches if it contains the filter anywhere in it.
After selection, retrieve your selection by accessing attributes sel_index or sel_dict. sel_index is a list of indexes into the provided lists. sel_dict is a dictionary with the keys being the indexes and the values being another dictionary of header : list-item pairs.
Example code:
from pyyeti import guitools headers = ['First', 'Middle', 'Last'] lst1 = ['Tony', 'Jennifer', 'Albert', 'Marion'] lst2 = ['J.', 'M.', 'E.', 'K.'] lst3 = ['Anderson', 'Smith', 'Kingsley', 'Cotter'] ind = guitools.MultiColumnListbox( 'Select person', headers, [lst1, lst2, lst3] ).sel_index[0] print(f'First Person is {lst1[ind]} {lst2[ind]} {lst3[ind]}')
Or, using the sel_dict attribute:
dct = guitools.MultiColumnListbox( 'Select person', headers, [lst1, lst2, lst3] ).sel_dict key = sorted(dct)[0] vals = dct[key] print(f"First Person is {vals['First']} {vals['Middle']} " f"{vals['Last']}")
- __init__(title, headers, lists, topstring='Click on header to sort by that column;\nDrag boundary to change width of column')[source]¶
Initialize a
MultiColumnListboxinstance.- Parameters:
title (string) – Title for the window
headers (list of strings) – List of column headers
lists (list of lists) – Corresponds to headers. Each list must be the same length and contain the contents of the columns. The contents are expected to be strings.
topstring (string; optional) – String to print above table
Methods
__init__(title, headers, lists[, topstring])Initialize a
MultiColumnListboxinstance.