⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des méthodes
tkinter.focus_force ( )
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des méthodes
tkinter.focus_force ( )
DESCRIPTION.
Donne le focus au controle appelant.
SYNTAXE.
widget.focus_force ( )
widget ⇨ controle quelconque de l'interface [ OBLIGATOIRE ]
.focus_force ( ) ⇨ appel de la méthode [ OBLIGATOIRE ]
REMARQUES.
L'emploi de la méthode tkinter.focus_force ( ) doit ce faire avec parcimonie. Il vaut mieux attendre que le programme donne le focus au controle suite à une action de l'utilisateur.
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.
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