⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des attributs
tkinter.anchor
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ liste des attributs
tkinter.anchor
DESCRIPTION.
Définit ou retourne la position du texte, ou de l'image, dans son controle.
SYNTAXE.
anchor = ancre
REMARQUES.
ancre doit être un str ( ) représentant une ancre valide. Les ancres valides sont :
- "n", centrer en haut ;
- "ne", en haut à droite ;
- "e", center à droite ;
- "se", en bas à droite ;
- "s", centrer en bas ;
- "sw", en bas à gauche ;
- "w", centrer à gauche ;
- "nw", en haut à gauche ;
- "center", centrer dans le conteneur (valeur par défaut).
Si le contenu du controle comporte plusieurs ligne de texte, l'attribut justify permet de choisir l'alignement des lignes entre elles.
EXEMPLE.
import tkinter
def FNC_Alignement ( Q ) :
LAB_Temoin [ "justify" ] = Q
FNC_Attibuts ( )
def FNC_Ancre ( event ) :
kancre = BOX_Ancres.get ( BOX_Ancres.curselection ( ) )
LAB_Temoin [ "anchor" ] = kancre
FNC_Attibuts ( )
def FNC_Attibuts ( ) :
kalignement = LAB_Temoin [ "justify" ]
kancre = LAB_Temoin [ "anchor" ]
LAB_Temoin [ "text" ] = f'Mon Pyhon à moi.\nanchor = "{ kancre }"\njustify = "{ kalignement }"'
TKI_Principal = tkinter.Tk ( )
BUT_Quitter = tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy )
BUT_Gauche = tkinter.Button ( TKI_Principal , text = "left" , command = lambda : FNC_Alignement ( "left" ) )
BUT_Milieu = tkinter.Button ( TKI_Principal , text = "center" , command = lambda : FNC_Alignement ( "center" ) )
BUT_Droite = tkinter.Button ( TKI_Principal , text = "right" , command = lambda : FNC_Alignement ( "right" ) )
BOX_Ancres = tkinter.Listbox ( TKI_Principal , height = 9 , width = 7 )
LAB_Temoin = tkinter.Label ( TKI_Principal , relief = "solid" , bd = 3 , height = 5 , width = 25 )
BOX_Ancres.grid ( row = 0 , column = 0 , rowspan = 3 , sticky = "nesw" )
LAB_Temoin.grid ( row = 0 , column = 1 , columnspan = 3 , sticky = "nesw" )
BUT_Gauche.grid ( row = 1 , column = 1 , sticky = "nesw" )
BUT_Milieu.grid ( row = 1 , column = 2 , sticky = "nesw" )
BUT_Droite.grid ( row = 1 , column = 3 , sticky = "nesw" )
BUT_Quitter.grid ( row = 2 , column = 1 , columnspan = 3 , sticky = "nesw" )
for kancre in ( "n" , "ne" , "e" , "se" , "s" , "sw" , "w" , "nw" , "center" ) :
BOX_Ancres.insert ( "end" , kancre )
BOX_Ancres.bind ( "<ButtonRelease>" , FNC_Ancre )
BOX_Ancres.bind ( "<KeyRelease-Up>" , FNC_Ancre )
BOX_Ancres.bind ( "<KeyRelease-Down>" , FNC_Ancre )
FNC_Alignement ( "center" )
BOX_Ancres.select_set ( 0 )
BOX_Ancres.focus_force ( )
FNC_Attibuts ( )
TKI_Principal.mainloop ( )
Votre aide est précieuse pour améliorer ce site, alors n'hésitez pas à faire part de