⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des attributs
tkinter.invalidcommand
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des attributs
tkinter.invalidcommand
DESCRIPTION.
Indique la fonction à exécuter si la fonction de validation du contenu d'un champ de saisie retourne False.
SYNTAXE.
invalidcommand = 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.
Voir la méthode tkinter.register ( ) pour plus d'informations sur la surveillance du contenu d'un champs de saisie.
EXEMPLE.
import tkinter
def FNC_Test ( Q ) :
if Q.isdigit ( ) :
LAB_Reponce [ "text" ] = f"Moitié = { int ( Q ) / 2 }\nDouble = { int ( Q ) * 2 }\nCarré = { int ( Q ) ** 2 }"
return True
else :
return False
def FNC_Message ( ) :
LAB_Reponce [ "text" ] = "ATTENTION !\nMauvaise\nsaisie !"
TKI_Principal = tkinter.Tk ( )
REG_Valide = TKI_Principal.register ( FNC_Test )
BUT_Quitter = tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy )
ENT_Texte = tkinter.Entry ( TKI_Principal , validate = "key" , validatecommand = ( REG_Valide , "%P" ) , invalidcommand = FNC_Message )
LAB_Reponce = tkinter.Label ( TKI_Principal , text = "Entrez un\nnombre\nentier" )
LAB_Reponce.pack ( )
ENT_Texte.pack ( )
BUT_Quitter.pack ( )
ENT_Texte.focus_force ( )
TKI_Principal.mainloop ( )
Votre aide est précieuse pour améliorer ce site, alors n'hésitez pas à faire part de