⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des méthodes
tkinter.focus_get ( )
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des méthodes
tkinter.focus_get ( )
DESCRIPTION.
Retourne le nom du controle ayant le focus.
SYNTAXE.
IDE_Objet = widget.focus_get ( )
IDE_Objet = ⇨ variable qui recevra la valeur [ optionnel ]
widget ⇨ controle quelconque de l'interface [ OBLIGATOIRE ]
.focus_get ( ) ⇨ appel de la méthode [ OBLIGATOIRE ]
REMARQUES.
Le focus désigne la focalisation du clavier. Quand un controle obtient, reçoit, acquièrent, le focus c'est vers lui que les saisies, faites au clavier par l’utilisateur, seront dirigées.
Par convention, on utilise la fenêtre créée avec tkinter.Tk ( ) pour l'utilisation de cette méthode.
EXEMPLE.
import tkinter
def FNC_Message ( event ) :
LAB_Focus [ "text" ] = f"{ TKI_Principal.focus_get ( ) } a le focus."
TKI_Principal = tkinter.Tk ( )
BUT_Quitter = tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy )
ENT_A = tkinter.Entry ( TKI_Principal )
ENT_B = tkinter.Entry ( TKI_Principal )
ENT_C = tkinter.Entry ( TKI_Principal )
BUT_A = tkinter.Button ( TKI_Principal , text = "focus⇒" , command = ENT_A.focus_force )
BUT_B = tkinter.Button ( TKI_Principal , text = "focus⇘" , command = ENT_C.focus_force )
BUT_C = tkinter.Button ( TKI_Principal , text = "focus⇗" , command = ENT_B.focus_force )
LAB_Focus = tkinter.Label ( TKI_Principal , text = "focus ?" )
ENT_A.bind ( "<FocusIn>" , FNC_Message )
ENT_B.bind ( "<FocusIn>" , FNC_Message )
ENT_C.bind ( "<FocusIn>" , FNC_Message )
LAB_Focus.grid ( row = 0 , column = 0 , columnspan = 2 , sticky = "nesw" )
BUT_A.grid ( row = 1 , column = 0 , sticky = "nesw" )
ENT_A.grid ( row = 1 , column = 1 , sticky = "nesw" )
BUT_B.grid ( row = 2 , column = 0 , sticky = "nesw" )
ENT_B.grid ( row = 2 , column = 1 , sticky = "nesw" )
BUT_C.grid ( row = 3 , column = 0 , sticky = "nesw" )
ENT_C.grid ( row = 3 , column = 1 , sticky = "nesw" )
BUT_Quitter.grid ( row = 0 , column = 2 , rowspan = 4 , sticky = "nesw" )
TKI_Principal.mainloop ( )
Votre aide est précieuse pour améliorer ce site, alors n'hésitez pas à faire part de