⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ controles standards ⇨ Text
tkinter.Text ( ).get ( )
⇨ MENU ⇨ MODULES ⇨ tkinter ⇨ controles standards ⇨ Text
tkinter.Text ( ).get ( )
DESCRIPTION.
Retourne les éléments caractères d'un éditeur de texte compris entre deux index.
SYNTAXE.
Variable = TXT_Editeur.get ( debut , fin )
Variable = ⇨ variable qui recevra le contenu [ optionnel ]
TXT_Editeur ⇨ instance quelconque de tkinter.Text ( ) [ OBLIGATOIRE ]
.get ( ) ⇨ appel de la méthode [ OBLIGATOIRE ]
debut ⇨ index du premier élément inclus [ OBLIGATOIRE ]
fin ⇨ index du dernier élément exclus [ optionnel ]
REMARQUES.
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. L'index debut est inclus dans la recherche mais l'index fin en est exclu. Si fin est absent, seul élément à l'index debut est traité. si fin précède debut, l'appel de la méthode tkinter.Text ( ).get ( ) est ignoré.
EXEMPLE.
import tkinter , tkinter.filedialog
def FNC_Copier ( Q ) :
TXT_Cible.delete ( "1.0" , "end" )
try :
ktexte = TXT_Source.get ( "1.0" , "end" ) if Q == "all" else TXT_Source.get ( "sel.first" , "sel.last" )
TXT_Cible.insert ( "end" , ktexte )
except :
pass
def FNC_Ouvrir ( ) :
kextentions = [ ( "texte" , ".txt" ) , ( "python" , ".py" ) ]
kfichier = tkinter.filedialog.askopenfilename ( title = "Ouvrir" , filetypes = kextentions )
if len ( kfichier ) < 1 : return
TXT_Source.delete ( "1.0" , "end" )
with open ( kfichier ) as FIL_Fichier : TXT_Source.insert ( "end" , FIL_Fichier.read ( ) )
TKI_Principal = tkinter.Tk ( )
BUT_Quitter = tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy )
BUT_Ouvrir = tkinter.Button ( TKI_Principal , text = "Ouvrir un fichier" , command = FNC_Ouvrir )
BUT_Tous = tkinter.Button ( TKI_Principal , text = "Cloner le texte" , command = lambda : FNC_Copier ( "all" ) )
BUT_Selection = tkinter.Button ( TKI_Principal , text = "Copier la sélection" , command = lambda : FNC_Copier ( "sel" ) )
TXT_Source = tkinter.Text ( TKI_Principal , wrap = "word" , width = 40 , height = 12 )
TXT_Cible = tkinter.Text ( TKI_Principal , wrap = "word" , width = 40 , height = 12 )
TXT_Source.grid ( row = 0 , column = 0 , sticky = "nesw" )
TXT_Cible.grid ( row = 0 , column = 1 , sticky = "nesw" )
BUT_Tous.grid ( row = 1 , column = 0 , sticky = "nesw" )
BUT_Ouvrir.grid ( row = 1 , column = 1 , sticky = "nesw" )
BUT_Selection.grid ( row = 2 , column = 0 , sticky = "nesw" )
BUT_Quitter.grid ( row = 2 , column = 1 , sticky = "nesw" )
TXT_Source.focus_force ( )
TKI_Principal.mainloop ( )
Votre aide est précieuse pour améliorer ce site, alors n'hésitez pas à faire part de