⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des méthodes
tkinter.grid_bbox ( )
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des méthodes
tkinter.grid_bbox ( )
DESCRIPTION.
Retourne la position, dans son conteneur, et la taille d'une case.
SYNTAXE.
TPL_Valeurs = widget.grid_bbox ( colonne , ligne , colonnes , lignes )
TPL_Valeurs = ⇨ variable qui recevra les valeurs [ optionnel ]
widget ⇨ conteneur quelconque de l'interface [ OBLIGATOIRE ]
.grid_bbox ( ) ⇨ appel de la méthode [ OBLIGATOIRE ]
colonne ⇨ index de la colonne [ optionnel ]
ligne ⇨ index de la ligne [ optionnel ]
colonnes ⇨ nombre de colonnes contiguës [ optionnel ]
colonne ⇨ nombre de lignes contiguës [ optionnel ]
REMARQUES.
colonne, ligne, colonnes et lignes doit être des int ( ).
La méthode tkinter.grid_bbox ( ) doit être employée avec 0, 2 ou 4 arguments, mais elle retourne toujours un tuple ( ) de 4 éléments. Les valeurs retournées sont exprimées en pixels.
Utilisée sans argument tkinter.grid_bbox ( ), les éléments du tuple ( ) donnent dans l'ordre :
- la distance entre le bord gauche du conteneur et la bord gauche de la première colonne (index 0) ;
- la distance entre le bord haut du conteneur et la bord haut de la première ligne (index 0) ;
- la largeur totale de toutes les colonnes, c'est-à-dire des lignes ;
- la hauteur totale de toutes les lignes, c'est-à-dire des colonnes.
Utilisée avec 2 arguments tkinter.grid_bbox ( ), les éléments du tuple ( ) donnent dans l'ordre :
- la distance entre le bord gauche du conteneur et la bord gauche de la colonne à index colonne ;
- la distance entre le bord haut du conteneur et la bord haut de la ligne à index ligne ;
- la largeur de la colonne ayant l'index colonne ;
- la hauteur de la ligne ayant index ligne.
Utilisée avec 4 arguments tkinter.grid_bbox ( ), les éléments du tuple ( ) donnent dans l'ordre :
- la distance entre le bord gauche du conteneur et la bord gauche de la colonne à index colonne ;
- la distance entre le bord haut du conteneur et la bord haut de la ligne à index ligne ;
- la largeur cumulée des colonnes colonnes contiguës à la colonne à l'index colonne ;
- la hauteur cumulée des lignes lignes contiguës à la lignes à l'index ligne ;
EXEMPLE.
import tkinter
def FNC_Afficher ( event ) :
kligne = int ( SCA_Ligne.get ( ) )
kvertical = int ( SCA_Vertical.get ( ) )
kcolonne = int ( SCA_Colonne.get ( ) )
khorizontal = int ( SCA_Horizontal.get ( ) )
LAB_Zero [ "text" ] = f"grid_bbox ( ) retourne { FRA_Apercu.bbox ( ) }"
LAB_Deux [ "text" ] = f"grid_bbox ( { kcolonne } , { kligne } ) retourne { FRA_Apercu.bbox ( kcolonne , kligne ) }"
LAB_Quatre [ "text" ] = f"grid_bbox ( { kcolonne } , { kligne } , { khorizontal } , { kvertical } ) retourne { FRA_Apercu.bbox ( kcolonne , kligne , khorizontal , kvertical ) } "
LAB_Origine.grid ( row = kligne , column = kcolonne )
LAB_Global.grid ( row = kligne , column = kcolonne )
if kvertical != 0 : LAB_Global.grid ( rowspan = kvertical )
if khorizontal != 0 : LAB_Global.grid ( columnspan = khorizontal )
# --- Creation de l'interface ---
# --- Creation de la fenetre principale ---
TKI_Principal = tkinter.Tk ( )
LAB_Zero = tkinter.Label ( TKI_Principal , fg = "black" , bg = "white" , justify = "left" , anchor = "w" )
LAB_Deux = tkinter.Label ( TKI_Principal , fg = "red" , bg = "yellow" , justify = "left" , anchor = "w" )
LAB_Quatre = tkinter.Label ( TKI_Principal , fg = "blue" , bg = "aqua" , justify = "left" , anchor = "w" )
# --- Creation du cadre des commandes dans la fenetre principale ---
FRA_Commande = tkinter.LabelFrame ( TKI_Principal , text = " COMMANDES " , labelanchor = "n" )
BUT_Quitter = tkinter.Button ( FRA_Commande , text = "Quitter" , command = TKI_Principal.destroy )
SCA_Ligne = tkinter.Scale ( FRA_Commande , orient = "horizontal" , from_ = 0 , to = 4 , command = FNC_Afficher )
SCA_Vertical = tkinter.Scale ( FRA_Commande , orient = "horizontal" , from_ = 0 , to = 5 , command = FNC_Afficher )
SCA_Colonne = tkinter.Scale ( FRA_Commande , orient = "horizontal" , from_ = 0 , to = 4 , command = FNC_Afficher )
SCA_Horizontal = tkinter.Scale ( FRA_Commande , orient = "horizontal" , from_ = 0 , to = 5 , command = FNC_Afficher)
# --- Placement des controles dans le cadre des commandes ---
tkinter.Label ( FRA_Commande , text = "row " , justify = "right" ).grid ( row = 0 , column = 0 , sticky = "se" )
SCA_Ligne.grid ( row = 0 , column = 1 , sticky = "nesw" )
tkinter.Label ( FRA_Commande , text = "rowspan " , justify = "right" ).grid ( row = 1 , column = 0 , sticky = "se" )
SCA_Vertical.grid ( row = 1 , column = 1 , sticky = "nesw" )
tkinter.Label ( FRA_Commande , text = "column " , justify = "right" ).grid ( row = 2 , column = 0 , sticky = "se" )
SCA_Colonne.grid ( row = 2 , column = 1 , sticky = "nesw" )
tkinter.Label ( FRA_Commande , text = "columnspan " , justify = "right" ).grid ( row = 3 , column = 0 , sticky = "se" )
SCA_Horizontal.grid ( row = 3 , column = 1 , sticky = "nesw" )
BUT_Quitter.grid ( row = 4 , column = 0 , columnspan = 2 , sticky = "sew" )
# --- Creation du cadre des resultats dans la fenetre principale ---
FRA_Apercu = tkinter.LabelFrame ( TKI_Principal , text = " APERCU " , labelanchor = "n" )
for kligne in range ( 5 ) :
for kcolonne in range ( 5 ) :
ktexte = f"row = { kligne }\ncolumn = { kcolonne }"
klabel = tkinter.Label ( FRA_Apercu , text = ktexte , relief = "solid" , bd = 2 , padx = 3 , pady = 3 )
klabel.grid ( row = kligne , column = kcolonne , padx = 1 , pady = 1 , sticky = "nesw" )
LAB_Global = tkinter.Label ( FRA_Apercu , text = "(⇐,⇑,⇔,⇕)" , bg = "aqua" , relief = "ridge" , bd = 4 )
LAB_Origine = tkinter.Label ( FRA_Apercu , text = "(⇐,⇑)" , fg = "red" , bg = "yellow" , relief = "ridge" , bd = 5 )
# --- Placement des autres controles du cadre des resultats ---
LAB_Global.grid ( row = 0 , column = 0 , sticky = "nesw" )
LAB_Origine.grid ( row = 0 , column = 0 , sticky = "nesw" )
# --- Placement des controles dans la fenetre principale ---
FRA_Commande.grid ( row = 0 , column = 0 , sticky = "nesw" )
FRA_Apercu.grid ( row = 0 , column = 1 , sticky = "nesw" )
LAB_Zero.grid ( row = 1 , column = 0 , columnspan = 2 , sticky = "nesw" )
LAB_Deux.grid ( row = 2 , column = 0 , columnspan = 2 , sticky = "nesw" )
LAB_Quatre.grid ( row = 3 , column = 0 , columnspan = 2 , sticky = "nesw" )
# --- Initialisation et affichage du premier code ---
FNC_Afficher ( None )
# --- Lancement de la boucle d'attente d'événements ---
TKI_Principal.mainloop ( )
Votre aide est précieuse pour améliorer ce site, alors n'hésitez pas à faire part de