⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ extension ttk ⇨ Treeview
tkinter.ttk.Treeview ( ).set_children ( )
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ extension ttk ⇨ Treeview
tkinter.ttk.Treeview ( ).set_children ( )
DESCRIPTION.
Change la liste des enfants d'un élément d'un objet tkinter.ttk.Treeview ( ).
SYNTAXE.
TRV_Tableau.set_children ( parent , elementA , ... , elementN )
TRV_Tableau ⇨ instance de tkinter.ttk.Treeview ( ) [ OBLIGATOIRE ]
.set_children ( ) ⇨ appel de la méthode [ OBLIGATOIRE ]
parent ⇨ identifiant du parent [ OBLIGATOIRE ]
element ⇨ identifiant de l'élément [ optionnel ]
REMARQUES.
parent et element sont des 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.
La méthode tkinter.ttk.Treeview ( ).set_children ( ) détache tous les éléments enfants de parent avant d'y placer les éléments passés en paramètres. Utilisée sans autre argument que parent, la méthode tkinter.ttk.Treeview ( ).set_children ( ) détache, cache, tous les éléments enfants de parent.
Tous les enfants précédemment dans parent sont détachés de parent. Il faut donc soit :
- les replacer dans la liste des nouveaux enfants dans l'appel de tkinter.ttk.Treeview ( ).set_children ( ) ;
- les afficher à leur nouvel emplacement avec la méthodes tkinter.ttk.Treeview ( ).move ( ) ;
- les laisser cachés.
EXEMPLE.
import tkinter , tkinter.ttk
def FNC_Modifier ( ) :
if BUT_Modifier [ "text" ] == "Vider E.U." :
BUT_Modifier [ "text" ] = "Remplir E.U."
TRV_Pays.set_children ( "eu" )
TRV_Pays.move ( "eu.be" , "" , "end" )
TRV_Pays.move ( "eu.fr" , "" , "end" )
TRV_Pays.move ( "eu.lu" , "" , "end" )
else :
BUT_Modifier [ "text" ] = "Vider E.U."
TRV_Pays.set_children ( "eu" , "eu.be" , "eu.fr" , "eu.lu" )
TKI_Principal = tkinter.Tk ( )
BUT_Quitter = tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy )
BUT_Modifier = tkinter.Button ( TKI_Principal , text = "Vider E.U." , command = FNC_Modifier )
TRV_Pays = tkinter.ttk.Treeview ( TKI_Principal )
TRV_Pays.heading ( "#0" , text = "Pays" , anchor = "w" )
TRV_Pays.insert ( "" , "end" , "ca" , text = "Canada" )
TRV_Pays.insert ( "" , "end" , "su" , text = "Suisse" )
TRV_Pays.insert ( "" , "end" , "eu" , text = "Union Européenne" , open = True )
TRV_Pays.insert ( "" , "end" , "an" , text = "Andorre" )
TRV_Pays.insert ( "" , "end" , "al" , text = "Algerie" )
TRV_Pays.insert ( "" , "end" , "ma" , text = "Maroc" )
TRV_Pays.insert ( "" , "end" , "li" , text = "Liban" )
TRV_Pays.insert ( "eu" , "end" , "eu.be" , text = "Belgique" )
TRV_Pays.insert ( "eu" , "end" , "eu.fr" , text = "France" )
TRV_Pays.insert ( "eu" , "end" , "eu.lu" , text = "Luxembourg" )
TRV_Pays.pack ( )
BUT_Modifier.pack ( )
BUT_Quitter.pack ( )
TKI_Principal.mainloop ( )
Votre aide est précieuse pour améliorer ce site, alors n'hésitez pas à faire part de