⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ extension ttk ⇨ Treeview
tkinter.ttk.Treeview ( ).selection ( )
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ extension ttk ⇨ Treeview
tkinter.ttk.Treeview ( ).selection ( )
DESCRIPTION.
Retourne la liste des éléments sélectionnés dans un objet tkinter.ttk.Treeview ( ).
SYNTAXE.
TPL_Valeur = TRV_Tableau.selection ( )
TPL_Valeur = ⇨ variable qui recevra le tuple ( ) [ optionnel ]
TRV_Tableau ⇨ instance de tkinter.ttk.Treeview ( ) [ OBLIGATOIRE ]
.selection ( ) ⇨ appel de la méthode [ OBLIGATOIRE ]
EXEMPLE.
import tkinter , tkinter.ttk
def FNC_Selection ( event ) :
kselection = TRV_Fruits.selection ( )
kmessage = "Eléments sélectionnés :\n"
for kfruit in kselection : kmessage += f"- { kfruit }\n"
TKV_Selection.set ( kmessage )
TKI_Principal = tkinter.Tk ( )
TKV_Selection = tkinter.StringVar ( )
TRV_Fruits = tkinter.ttk.Treeview ( TKI_Principal )
TRV_Fruits.heading ( "#0" , text = "Fruit" )
for kfruit in ( "Cerise" , "Abricot" , "Fraise" , "Pomme" , "Banane" , "Poire" , "Ananas" , "Kiwi" , "Prune" ) :
TRV_Fruits.insert ( "" , "end" , kfruit.lower ( ) , text = kfruit )
TRV_Fruits.bind ( "<<TreeviewSelect>>", FNC_Selection )
TRV_Fruits.pack ( fill = "both" )
tkinter.Label ( TKI_Principal , textvariable = TKV_Selection , anchor = "w" , justify = "left" ).pack ( )
tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy ).pack ( )
TKI_Principal.mainloop ( )
Votre aide est précieuse pour améliorer ce site, alors n'hésitez pas à faire part de