import tkinter as tk from tkinter import ttk from tkinter.messagebox import showinfo ruledesigner_ids = ( '400102274', '400102275', '400102190', '400102198', '400102161', '400102277', '400102163', '400102278', '400102282', '400102284', '400102195', 'MA0000008', 'MA0000004', '929055170', '400102267', '400102235', '400102236', 'MA0000006', '400102237', '400102238', '400102239', '400102268', '829416159', '924031058', '924031081', '822064091', '822066199', '822066200') parent_children_mapping = {'400102196': ['400102125', '400102126', '400102130', '400102161', '400102163', '400102165', '400102166', '400102167', '400102168', '400102190', '400102195', '400102198', '400102246', '400102247', '400102267', '400102272', '400102274', '400102275', '400102277', '400102278', '400102282', '400102284', '400102417', '720002003', '721001034', '821114025', '822064091', '822066085', '822996075', '829416061', '829516004', '911021113', '911021181', '911021259', '911091054', '911091096', '911091097', '911251013', '912011009', '919050006', '924031058', '924031081'], '400102282': ['822066026', '822066089', '919010052'], '400102195': [ '822066075', '822066216', '822066154', '822066101', '822064090', '822066196', '400102129', '822066217', '822066160', '822066215', '913041045', '913011009', '911011057', '822064035', '925011006', '911091041', '913051040', '911021112', '911021166', '825006003', '912041005', '911011014', '911011009', '911021144', '911021001', '913011016', '929055170', '913011010', '911021035', '829416065', '712000151', '712000100'], '822066075': ['822066157', '822066162', '911261023'], '822066162': [ '822064013'], '822066196': ['MA0000008'], '822066160': ['MA0000004'], '822064035': ['822066065'], '822064093': ['822066204', '822066205', '822066206', '822066207', '822066208'], '822066220': ['924031033'], '822064091': ['822066212', '822064093', '822066220', '822066200', '912011010', '911021156', '822066201', '911071027', '913011109', '911011070', '913011001', '710005021', '919010055', '720000008', '720000007'], '400102267': ['400102235', '829416159', '829416077', '829416079', '911021260', '911021147', '911251014'], '400102235': ['400102236', '400102237', '400102238', '400102239', '400102268', '911021143', '911021054', '911021055'], '400102236': ['MA0000006'], '829416159': ['829416089'], '400102130': ['400102142'], '821116004': ['822026004'], '400102168': ['821116001'], '821114025': ['911081007', '821116053'], '400102167': ['821116004']} root_num = "400102196" # create root window root = tk.Tk() root.title('Treeview Demo - Hierarchical Data') root.geometry('400x200') # configure the grid layout root.rowconfigure(0, weight=1) root.columnconfigure(0, weight=1) # create a treeview tree = ttk.Treeview(root) # TODO hier anstatt root die Statistik rein schreiben. tree.heading('#0', text='root', anchor=tk.W) # adding data of first column after root pool = set() for parent,children in parent_children_mapping.items(): if parent not in pool: tree.insert('', tk.END, text=parent, iid=parent, open=True) pool.add(parent) cn = children # sortiere die Zahlen im Baum immer aufsteigend cn.sort(reverse=True) for child_id in cn: if child_id not in pool: pool.add(child_id) if child_id not in ruledesigner_ids: rowtags = ('good') else: rowtags = ('missing') tree.insert('', tk.END, text=child_id, iid=child_id, tags=rowtags, open=True) #tree.move(child_id, parent, 0) # einmal über alles gehen und alle keys an die richtige Stelle schieben for parent,children in parent_children_mapping.items(): for child_id in children: tree.move(child_id, parent, 0) # https://www.askpython.com/python-modules/tkinter/tkinter-colors #tree.tag_configure('good', background='LawnGreen') tree.tag_configure('good', background='white') tree.tag_configure('missing', background='red') # place the Treeview widget on the root window tree.grid(row=0, column=0, sticky=tk.NSEW) # run the app root.mainloop()