Bonjour,
J'alimente une TreeView avec la fonction '.insert()'. Ma TreeView à plusieurs colonnes, je voudrais que le tri ne se fasse que sur la colonne Date (de la plus récente à la plus ancienne).
Je ne veux pas de fonction tri lorsque l'on clic sur le heading de la treeview. D'ailleurs j'ai un soucis avec ça car lorsque je double clic sur le heading je lance une fonction, or ne ne veux pas...
Ci joint mon code:
Ma treeview:
Ma fonction 'sort_treeview':
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 tree_yscrollbar = Scrollbar(ListView_frame) tree_yscrollbar.pack(side=RIGHT, fill=Y) style = ttk.Style() style.configure("Treeview.Heading", font=('Courier new', 10)) style.configure("Treeview", font=('Courier new', 10)) tree["columns"] = ("Column_1","Column_2", "Column_3", "Column_4") tree.column("#0", width=230, minwidth=0) tree.column("Column_1", width=175, minwidth=0) tree.column("Column_2", width=70, minwidth=0) tree.column("Column_3", width=450, minwidth=0) tree.column("Column_4", width=150, minwidth=0) tree.heading("#0", text="Nom", anchor=tk.W) tree.heading("Column_1", text="Date", anchor=tk.W) tree.heading("Column_2", text="Taille", anchor=tk.W) tree.heading("Column_3", text="Chemin", anchor=tk.W) tree.heading("Column_4", text="Port FTP", anchor=tk.W) tree.pack(side=LEFT, expand=True, fill=BOTH) tree.bind('<Double-1>', lambda e: FTP_OpenSelectedFile()) tree_yscrollbar.config(command=tree.yview)
Le remplissage de ma treeview:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 def sort_treeview(): content = [(tree.set(child, column), child) for child in tree.get_children('')] try: content.sort(key=lambda t: int(t[0])) except: content.sort() for index, (val, child) in enumerate(content): tree.move(child, '', index)
Merci par avance.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 for i in FilteredFiles: DT_convertion(ftp, i) tree.insert('', 'end', text=i, values=(DT_convertion(ftp, i), ftp.size(i), FTP_PATH+Cell_folder+'/'+i, PORT)) sort_treeview() iFile +=1
Partager