⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ controles standards ⇨ Text
tkinter.Text ( ).tag_remove ( )
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ controles standards ⇨ Text
tkinter.Text ( ).tag_remove ( )
DESCRIPTION.
Annule un style de formatage associé à une portion du contenu d'un éditeur de texte.
SYNTAXE.
TXT_Editeur.tag_remove ( format , debut , fin )
TXT_Editeur ⇨ instance quelconque de tkinter.Text ( ) [ OBLIGATOIRE ]
.tag_remove ( ) ⇨ 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_Appliquer ( ) :
try :
kformat = LAB_Format [ "text" ]
if kformat == "" :
LAB_Message [ "text" ] = f"Créez d'abord un format (tag) ..."
return
TXT_Editeur.tag_add ( kformat , "sel.first" , "sel.last" )
LAB_Message [ "text" ] = f"{ kformat } a été appliqué ..."
except :
LAB_Message [ "text" ] = f"Faites une sélection ..."
def FNC_Dissocier ( ) :
try :
kformat = LAB_Format [ "text" ]
if kformat == "" :
LAB_Message [ "text" ] = f"Créez d'abord un format (tag) ..."
return
TXT_Editeur.tag_remove ( kformat , "sel.first" , "sel.last" )
TXT_Editeur.tag_remove ( "sel" , "sel.first" , "sel.last" )
LAB_Message [ "text" ] = f"{ kformat } a été dissocié ..."
except :
LAB_Message [ "text" ] = f"Faites une sélection ..."
def FNC_Modifier ( ) :
kformat = LAB_Format [ "text" ]
if kformat == "" :
LAB_Message [ "text" ] = f"Créez d'abord un format (tag) ..."
return
kencre = SPI_Encre.get ( )
kfond = SPI_Fond.get ( )
kstyle = SPI_Style.get ( )
TXT_Editeur.tag_config ( kformat , foreground = kencre , background = kfond , font = ( None , 10 , kstyle ) )
LAB_Message [ "text" ] = f"{ kformat } ({ kencre } sur { kfond } en { kstyle } )"
def FNC_Nouveau ( ) :
kvaleur = len ( TXT_Editeur.tag_names ( ) )
kformat = f"Format_{ kvaleur }"
LAB_Format [ "text" ] = f"{ kformat }"
FNC_Modifier ( )
BOX_Liste.delete ( 0 , "end" )
for kformat in TXT_Editeur.tag_names ( ) :
if kformat != "sel" : BOX_Liste.insert ( "end" , kformat )
FNC_Appliquer ( )
def FNC_Selection ( event ) :
try :
kformat = BOX_Liste.get ( BOX_Liste.curselection ( ) )
kencre = TXT_Editeur.tag_cget ( kformat , "foreground" )
kfond = TXT_Editeur.tag_cget ( kformat , "background" )
kstyle = TXT_Editeur.tag_cget ( kformat , "font" )
LAB_Message [ "text" ] = f"{ kformat } ({ kencre } sur { kfond } en { kstyle }) est sélectionnée ..."
LAB_Format [ "text" ] = f"{ kformat }"
except :
LAB_Message [ "text" ] = f"Créez d'abord un format (tag) ..."
def FNC_Supprimer ( ) :
kformat = LAB_Format [ "text" ]
if kformat == "" :
LAB_Message [ "text" ] = f"Créez d'abord un format (tag) ..."
return
TXT_Editeur.tag_delete ( kformat )
BOX_Liste.delete ( 0 , "end" )
for kformat in TXT_Editeur.tag_names ( ) :
if kformat != "sel" : BOX_Liste.insert ( "end" , kformat )
LAB_Message [ "text" ] = f"{ kformat } a été supprimé ..."
LAB_Format [ "text" ] = ""
TKI_Principal = tkinter.Tk ( )
kcouleurs = ( "black" , "red" , "lime" , "blue" , "aqua" , "magenta" , "yellow" , "green" , "white" , "sienna" , "pink" , "palegreen" )
BUT_Quitter = tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy )
BUT_Nouveau = tkinter.Button ( TKI_Principal , text = "Créer" , command = FNC_Nouveau )
BUT_Modifier = tkinter.Button ( TKI_Principal , text = "Modifier" , command = FNC_Modifier )
BUT_Appliquer = tkinter.Button ( TKI_Principal , text = "Appliquer" , command = FNC_Appliquer )
BUT_Dissocier = tkinter.Button ( TKI_Principal , text = "Discocier" , command = FNC_Dissocier )
BUT_Supprimer = tkinter.Button ( TKI_Principal , text = "Supprimer" , command = FNC_Supprimer )
SPI_Encre = tkinter.Spinbox ( TKI_Principal , values = kcouleurs , wrap = True , width = 6 )
SPI_Fond = tkinter.Spinbox ( TKI_Principal , values = kcouleurs , wrap = True , width = 6 )
SPI_Style = tkinter.Spinbox ( TKI_Principal , values = ( "normal" , "bold" , "italic" ) , wrap = True , width = 6 )
BOX_Liste = tkinter.Listbox ( TKI_Principal )
LAB_Message = tkinter.Label ( TKI_Principal , relief = "ridge" , bd = 3 , justify = "left" , anchor = "w" )
LAB_Format = tkinter.Label ( TKI_Principal , relief = "ridge" , bd = 3 )
TXT_Editeur = tkinter.Text ( TKI_Principal , wrap = "none" , width = 80 , height = 25 )
BOX_Liste.bind ( "<ButtonRelease>" , FNC_Selection )
TXT_Editeur.grid ( row = 0 , column = 0 , columnspan = 5 , sticky = "nesw" )
BOX_Liste.grid ( row = 0 , column = 5 , sticky = "nesw" )
tkinter.Label ( TKI_Principal , text = "encre" , anchor = "s" ).grid ( row = 1 , column = 0 , sticky = "s" )
tkinter.Label ( TKI_Principal , text = "papier" , anchor = "s" ).grid ( row = 1 , column = 1 , sticky = "s" )
tkinter.Label ( TKI_Principal , text = "style" , anchor = "s" ).grid ( row = 1 , column = 2 , sticky = "s" )
LAB_Format.grid ( row = 1 , column = 5 , sticky = "nesw" )
SPI_Encre.grid ( row = 2 , column = 0 , sticky = "nesw" )
SPI_Fond.grid ( row = 2 , column = 1 , sticky = "nesw" )
SPI_Style.grid ( row = 2 , column = 2 , sticky = "nesw" )
BUT_Nouveau.grid ( row = 2 , column = 3 , sticky = "nesw" )
BUT_Modifier.grid ( row = 2 , column = 4 , sticky = "nesw" )
BUT_Supprimer.grid ( row = 2 , column = 5 , sticky = "nesw" )
LAB_Message.grid ( row = 3 , column = 0 , columnspan = 3 , sticky = "nesw" )
BUT_Appliquer.grid ( row = 3 , column = 3 , sticky = "nesw" )
BUT_Dissocier.grid ( row = 3 , column = 4 , sticky = "nesw" )
BUT_Quitter.grid ( row = 3 , column = 5 , sticky = "nesw" )
SPI_Encre.delete ( 0 , "end" )
SPI_Encre.insert ( 0 , "blue" )
SPI_Fond.delete ( 0 , "end" )
SPI_Fond.insert ( 0 , "aqua" )
TXT_Editeur.insert ( "1.0" , "Tapez votre texte ici ..." )
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