pythontkintertix

Tkinter: Best way to realize "Listbox with headings"


In Python I have a list of dictionaries that basically looks like this:

the_list = [{'name': "A", 'entries': [1, 2, 3]}, {'name': "B", 'entries': [4, 5, 6]}, ...] 

With Tkinter I want to let the user select one entry (here a number) from a listbox or something similar. The name, here "A" or "B" should be displayed but not selectable. The whole thing should have scrollbars in case the entries take more space than the window provides. For compatibilty reasons it would be best if only Tkinter is used, but if that makes things too complicated, Tix might be acceptable as well.

My first try was to use only one listbox and a scrollbar. However, that creates the problem that the names are listbox entries as well and therefore selectable.

My next idea was to use a Tix ScrolledWindow, inside which I generate Labels for the names and Listboxes for the entries.

However, before I try to realize that I want to ask whether there might be a much better solution.


Solution

  • You can use the ttk TreeView widget, which lets you have headings and multiple columns.

    For more information see http://www.tkdocs.com/tutorial/tree.html