⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des méthodes
tkinter.cget ( )
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des méthodes
tkinter.cget ( )
DESCRIPTION.
Retourne la valeur actuelle d'un l'attribut du controle.
SYNTAXE.
Variable = widget.cget ( attribut )
Variable = ⇨ variable qui recevra la valeur [ optionnel ]
widget ⇨ controle quelconque de l'interface [ OBLIGATOIRE ]
.cget ( ) ⇨ appel de la méthode [ OBLIGATOIRE ]
attribut ⇨ nom d'un attribut du controle [ OBLIGATOIRE ]
Variable = widget [ "attribut" ]
Variable = ⇨ variable qui recevra la valeur [ optionnel ]
widget ⇨ controle quelconque de l'interface [ OBLIGATOIRE ]
[ "attribut" ] ⇨ nom d'un attribut du controle [ OBLIGATOIRE ]
REMARQUES.
widget.cget ( attribut ) équivaut à widget [ "attribut" ]. attribut doit être un str ( ) valide correspondant l'un des attribut du controle appelant.
Voir aussi la méthode tkinter.keys ( ) qui permet de connaitre la liste de tous les attributs disponibles pour un controle.
EXEMPLE.
import tkinter
def FNC_Lecture ( Q ) :
kattributs = Q.keys ( )
kidentifiant = Q.winfo_id ( )
knom = Q.winfo_pathname ( kidentifiant )
LAB_Controle [ "text" ] = f"{ kidentifiant }\n{ knom }"
BOX_Attributs.delete ( 0 , "end" )
for kattribut in kattributs :
kvaleur = Q.cget ( kattribut )
kligne = f"{ kattribut } = { kvaleur }"
BOX_Attributs.insert ( "end" , kligne )
TKI_Principal = tkinter.Tk ( )
BUT_Quitter = tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy )
BUT_Bouton = tkinter.Button ( TKI_Principal , text = "Ce bouton" , command = lambda : FNC_Lecture ( BUT_Bouton ) )
BUT_Fenetre = tkinter.Button ( TKI_Principal , text = "La fenetre" , command = lambda : FNC_Lecture ( TKI_Principal ) )
BUT_Liste = tkinter.Button ( TKI_Principal , text = "La liste" , command = lambda : FNC_Lecture ( BOX_Attributs ) )
BUT_Etiquette = tkinter.Button ( TKI_Principal , text = "Le label" , command = lambda : FNC_Lecture ( LAB_Controle ) )
BOX_Attributs = tkinter.Listbox ( TKI_Principal , width = 25 )
LAB_Controle =tkinter.Label ( TKI_Principal , text = "faites un\nchoix..." , fg = "red" , bg = "yellow" )
BOX_Attributs.insert ( "end" , "en attente ..." )
BOX_Attributs.grid ( row = 0 , column = 0 , rowspan = 5 , sticky = "nesw" )
LAB_Controle.grid ( row = 0 , column = 1 , sticky = "nesw" )
BUT_Quitter.grid ( row = 0 , column = 2 , rowspan = 5 , sticky = "nesw" )
BUT_Bouton.grid ( row = 1 , column = 1 , sticky = "nesw" )
BUT_Fenetre.grid ( row = 2 , column = 1 , sticky = "nesw" )
BUT_Liste.grid ( row = 3 , column = 1 , sticky = "nesw" )
BUT_Etiquette.grid ( row = 4 , column = 1 , sticky = "nesw" )
TKI_Principal.mainloop ( )
Votre aide est précieuse pour améliorer ce site, alors n'hésitez pas à faire part de