⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ extension ttk ⇨ Treeview
tkinter.ttk.Treeview ( ).tag_has ( )
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ extension ttk ⇨ Treeview
tkinter.ttk.Treeview ( ).tag_has ( )
DESCRIPTION.
Associe un gestionnaire d'événements à tous les éléments d'une arborescence ayant la balise indiquée.
SYNTAXE.
TRV_Tableau.tag_has ( balise , element )
TRV_Tableau ⇨ instance de tkinter.ttk.Treeview ( ) [ OBLIGATOIRE ]
.tag_bind ( ) ⇨ appel de la méthode [ OBLIGATOIRE ]
balise ⇨ groupe d'éléments lié à l'événement [ OBLIGATOIRE ]
element ⇨ identifiant de l'élément [ optionnel ]
REMARQUES.
balise est un str ( ) quelconque qui représente l'élément ou le groupe d'éléments qui seront sensible à evenement. Tous les éléments peuvent recevoir un ou plusieurs tags. Les éléments possédant un tag commun, forment un groupe d'éléments, et ils pourront donc être appelés ensemble.
element est un str ( ) désignant l'identifiant d'un élément de l'arborescence. L'identifiant d'un élément est la chaine de caractères donnée en troisième argument dans la méthode tkinter.ttk.Treeview ( ).insert ( ). Si element n'existe pas, ou n'existe plus, Python lèvera une exception.
Utilisée sans l'argument element, la méthode tkinter.ttk.Treeview ( ).tag_has ( ) retourne, la liste des éléments associés à balise.
EXEMPLE.
import tkinter , tkinter.ttk
def FNC_Selection ( event ) :
kselection = TRV_Fruits.selection ( )
kbalises = TRV_Fruits.item ( kselection , "tags" )
kmessage = ""
for kbalise in kbalises :
kmessage += f"{ kbalise } :\n"
kelements = TRV_Fruits.tag_has ( kbalise )
for kelement in kelements : kmessage += f" - { kelement } \n"
kmessage += "\n"
TKV_Infos.set ( kmessage )
TKI_Principal = tkinter.Tk ( )
TKV_Infos = tkinter.StringVar ( )
TRV_Fruits = tkinter.ttk.Treeview ( TKI_Principal , selectmode = "browse" )
TRV_Fruits.heading ( "#0" , text = "Fruit" )
TRV_Fruits.insert ( "" , "end" , "cerise" , text = "Cerise" , tags = ( "rouge" , "noyau" ) )
TRV_Fruits.insert ( "" , "end" , "abricot" , text = "Abricot" , tags = ( "jaune" , "noyau" ) )
TRV_Fruits.insert ( "" , "end" , "myrtille" , text = "Myrtille" , tags = ( "rouge" , "pepin" ) )
TRV_Fruits.insert ( "" , "end" , "fraise" , text = "Fraise" , tags = "rouge" )
TRV_Fruits.insert ( "" , "end" , "pomme" , text = "Pomme" , tags = ( "jaune" , "pepin" ) )
TRV_Fruits.insert ( "" , "end" , "banana" , text = "Banane" , tags = "jaune" )
TRV_Fruits.insert ( "" , "end" , "poire" , text = "Poire" , tags = ( "jaune" , "pepin" ) )
TRV_Fruits.insert ( "" , "end" , "ananas" , text = "Ananas" , tags = "vert" )
TRV_Fruits.insert ( "" , "end" , "kiwi" , text = "Kiwi" , tags = ( "vert" , "pepin" ) )
TRV_Fruits.insert ( "" , "end" , "prune" , text = "Prune" , tags = ( "rouge" , "noyau" ) )
TRV_Fruits.bind ( "<<TreeviewSelect>>", FNC_Selection )
tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy ).pack ( )
TRV_Fruits.pack ( side = "left" )
tkinter.Label ( TKI_Principal , textvariable = TKV_Infos , anchor = "w" , justify = "left" ).pack ( )
TKI_Principal.mainloop ( )
Votre aide est précieuse pour améliorer ce site, alors n'hésitez pas à faire part de