⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des attributs
tkinter.command
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des attributs
tkinter.command
DESCRIPTION.
Définit ou retourne l'action à effectuer lorsque l'utilisateur clique sur le controle.
SYNTAXE.
command = fonction
REMARQUES.
fonction doit être une expression représentant une méthode, ou fonction, à exécuter. Il s'agit du nom de la méthode, ou de la fonction, sans les parenthèses, car tkinter n'autorise pas le passage d'argument avec l'attribut command. Si la méthode, ou fonction, attend un ou des attributs pour son exécution, il faut utiliser une méthode anonyme, lambda, pour transmettre ces attributs.
EXEMPLE.
import tkinter
def FNC_Moins ( ) :
LAB_Compteur [ "text" ] = int ( LAB_Compteur [ "text" ] ) - 1
LAB_Appel [ "text" ] = BUT_Moins [ "command" ]
def FNC_Plus ( ) :
LAB_Compteur [ "text" ] = int ( LAB_Compteur [ "text" ] ) + 1
LAB_Appel [ "text" ] = BUT_Plus [ "command" ]
def FNC_Valeur ( Q ) :
LAB_Compteur [ "text" ] = Q
if Q == "0" :
LAB_Appel [ "text" ] = BUT_Zero [ "command" ]
else :
LAB_Appel [ "text" ] = BUT_Cent [ "command" ]
TKI_Principal = tkinter.Tk ( )
BUT_Quitter = tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy )
BUT_Plus = tkinter.Button ( TKI_Principal , text = "Plus" , command = FNC_Plus )
BUT_Moins = tkinter.Button ( TKI_Principal , text = "Moins" , command = FNC_Moins )
BUT_Zero = tkinter.Button ( TKI_Principal , text = "RaZ" , command = lambda : FNC_Valeur ( "0" ) )
BUT_Cent = tkinter.Button ( TKI_Principal , text = "100" , command = lambda : FNC_Valeur ( "100" ) )
LAB_Appel = tkinter.Label ( TKI_Principal , text = "command ???" )
LAB_Compteur = tkinter.Label ( TKI_Principal , text = "50" )
LAB_Appel.pack ( fill = "both" )
LAB_Compteur.pack ( fill = "both" )
BUT_Zero.pack ( fill = "both" )
BUT_Plus.pack ( fill = "both" )
BUT_Moins.pack ( fill = "both" )
BUT_Cent.pack ( fill = "both" )
BUT_Quitter.pack ( fill = "both" )
TKI_Principal.mainloop ( )
Votre aide est précieuse pour améliorer ce site, alors n'hésitez pas à faire part de