⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ controles standards ⇨ Text
tkinter.Text ( ).tag_add ( )
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ controles standards ⇨ Text
tkinter.Text ( ).tag_add ( )
DESCRIPTION.
Applique un formatage à une portion du contenu d'un éditeur de texte.
SYNTAXE.
TXT_Editeur.tag_add ( format , debut , fin )
TXT_Editeur ⇨ instance quelconque de tkinter.Text ( ) [ OBLIGATOIRE ]
.tag_add ( ) ⇨ appel de la méthode [ OBLIGATOIRE ]
format ⇨ format à appliquer [ OBLIGATOIRE ]
debut ⇨ index du premier élément inclus [ OBLIGATOIRE ]
fin ⇨ index du dernier élément exclus [ optionnel ]
REMARQUES.
format est un str ( ) correspondant à un nom valide de formatage. Voir la méthode tkinter.Text ( ).tag_config ( ) pour plus détails sur les formatages. Si format n’existe pas, il est créer, mais sans aucune configuration.
debut et fin sont des str ( ) quelconques, mais valides, désignant un index dans un éditeur de texte. Un index valide a la forme : "paragraphe.place" ou un nom correspondant à une balise de position ou une position particulière. Voir la méthode tkinter.Text ( ).index ( ) pour plus d'informations sur les index.
EXEMPLE.
import tkinter
def FNC_Formater ( Q ) :
try : TXT_Editeur.tag_add ( Q , "sel.first" , "sel.last" )
except : pass
TKI_Principal = tkinter.Tk ( )
BUT_Quitter = tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy )
BUT_Bleu = tkinter.Button ( TKI_Principal , text = "Bleu" , command = lambda : FNC_Formater ( "bleu" ) )
BUT_Rouge = tkinter.Button ( TKI_Principal , text = "Rouge" , command = lambda : FNC_Formater ( "rouge" ) )
BUT_Vert = tkinter.Button ( TKI_Principal , text = "Vert" , command = lambda : FNC_Formater ( "vert" ) )
TXT_Editeur = tkinter.Text ( TKI_Principal , wrap = "word" , width = 40 , height = 12 )
TXT_Editeur.grid ( row = 0 , column = 0 , columnspan = 3 , sticky = "nesw" )
tkinter.Label ( TKI_Principal , text = "Mettre la sélection en ..." ).grid ( row = 1 , column = 0 , columnspan = 3 )
BUT_Bleu.grid ( row = 2 , column = 0 , sticky = "nesw" )
BUT_Rouge.grid ( row = 2 , column = 1 , sticky = "nesw" )
BUT_Vert.grid ( row = 2 , column = 2 , sticky = "nesw" )
BUT_Quitter.grid ( row = 3 , column = 0 , columnspan = 3 , sticky = "nesw" )
TXT_Editeur.tag_config ( "bleu" , foreground = "blue" , background = "aqua" )
TXT_Editeur.tag_config ( "rouge" , foreground = "red" , background = "pink" )
TXT_Editeur.tag_config ( "vert" , foreground = "green" , background = "palegreen" )
TXT_Editeur.insert ( "1.0" , "Python est puissant et facile à apprendre." )
TXT_Editeur.insert ( "end + 1 line" , "\n\n" )
TXT_Editeur.insert ( "end + 1 line" , "Extrait de la documentation officielle." )
TXT_Editeur.focus_force ( )
TKI_Principal.mainloop ( )
Votre aide est précieuse pour améliorer ce site, alors n'hésitez pas à faire part de