⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des méthodes
tkinter.grid_location ( )
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des méthodes
tkinter.grid_location ( )
DESCRIPTION.
Retourne la ligne et la colonne de la grille correspondants à des coordonnées en pixels.
SYNTAXE.
TPL_Case = widget.grid_location ( abscisse , ordonnee )
TPL_Case = ⇨ variable qui recevra les coordonnées [ optionnel ]
widget ⇨ conteneur quelconque de l'interface [ OBLIGATOIRE ]
.grid_location ( ) ⇨ appel de la méthode [ OBLIGATOIRE ]
abscisse ⇨ distance en pixels [ OBLIGATOIRE ]
ordonnee ⇨ distance en pixels [ OBLIGATOIRE ]
REMARQUES.
abscisse est un int ( ) indiquant une distance, en pixels, par rapport au bord gauche du conteneur de la grille. Si abscisse n'est pas dans le conteneur, tkinter.grid_location ( ) retourne -1 pour la valeur d'index de la colonne.
ordonnee est un int ( ) indiquant une distance, en pixels, par rapport au bord haut du conteneur de la grille. Si ordonnee n'est pas dans le conteneur, tkinter.grid_location ( ) retourne -1 pour la valeur d'index de la ligne.
tkinter.grid_location ( ) retourne un tuple ( ) de 2 éléments, où le premier l'élément est l'index de la colonne et le second élément est l'index de la ligne.
EXEMPLE.
import tkinter
def FNC_Lecture ( ) :
kabscisse = TKI_Principal.winfo_pointerx ( ) - TKI_Principal.winfo_x ( )
kordonnee = TKI_Principal.winfo_pointery ( ) - TKI_Principal.winfo_y ( )
kcoordonnees = TKI_Principal.grid_location ( kabscisse , kordonnee )
LAB_Souris [ "text" ] = f"Les coordonnées { kabscisse } x { kordonnee }\ncorrespondent à"
LAB_Ligne [ "text" ] = f"Ligne : { kcoordonnees [ 0 ] }"
LAB_colonne [ "text" ] = f"Colonne : { kcoordonnees [ 1 ] }"
TKI_Principal.after ( 200 , FNC_Lecture )
TKI_Principal = tkinter.Tk ( )
BUT_Quitter = tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy )
LAB_Souris = tkinter.Label ( TKI_Principal , text = "Souris : ?." )
LAB_Ligne = tkinter.Label ( TKI_Principal , text = "Ligne : ?." , width = 12 )
LAB_colonne = tkinter.Label ( TKI_Principal , text = "Colonne : ?." , width = 12 )
LAB_Souris.grid ( row = 0 , column = 0 , columnspan = 2 )
LAB_Ligne.grid ( row = 1 , column = 0 , pady = 10 )
LAB_colonne.grid ( row = 1 , column = 1 )
tkinter.Button ( TKI_Principal , text = "[ A ]" ).grid ( row = 3 , column = 0 )
tkinter.Button ( TKI_Principal , text = "[ B ]" ).grid ( row = 3 , column = 1 )
BUT_Quitter.grid ( row = 4 , column = 0 , columnspan = 2 )
FNC_Lecture ( )
TKI_Principal.mainloop ( )
Votre aide est précieuse pour améliorer ce site, alors n'hésitez pas à faire part de