How can I have the tkintertable table's columns sorted the way they are in the dictionary? How can I have the tkintertable table's columns sorted the way they are in the dictionary? tkinter tkinter

How can I have the tkintertable table's columns sorted the way they are in the dictionary?


There are two ways you can do this.

1. Use a predefined column order.

Right before model.importDict(data), you should define the columns on model:

columns = ['Klasa', 'E Hene', 'E Marte', 'E Merkurre', 'E Enjte', 'E Premte']for column in columns:    model.addColumn(column)

2. Use OrderedDict.

Wherever your data comes from (e.g., a CSV or database), you should make your row dictionaries using collections.OrderedDict:

import collectionsdata = {'1': collections.OrderedDict([('Klasa', '6A'), ('E Hene', 1), ('E Marte', 2), ('E Merkurre', 3), ('E Enjte', 4), ('E Premte', 5)]),        '2': collections.OrderedDict([('Klasa', ''), ('E Hene', 1), ('E Marte', 2), ('E Merkurre', 3), ('E Enjte', 4), ('E Premte', 5)])}