1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
from tkinter import *
def recherche(ev=None):
# Recherche.
nmbChar = IntVar()
lastPos = "1.0"
# Nombre.
while 1 :
liste_noms="(begin|item|input|sqrt)"
lastPos = texte.search(liste_noms, index = lastPos, stopindex = 'end', regexp = 1, count = nmbChar )
if lastPos == "" :
break
# Ajout d'un tag
texte.tag_add( 'bleu', lastPos, "%s + %d chars" % ( lastPos, nmbChar.get() ) )
lastPos = "%s + 1 chars" % lastPos
texte.tag_configure( 'bleu', foreground = 'blue',font=('courier',13))
lastPos = "1.0"
# Nombre.
while 1 :
liste_noms="((\{)(.*)(\}))"
lastPos = texte.search(liste_noms, index = lastPos, stopindex = 'end', regexp = 1, count = nmbChar )
if lastPos == "" :
break
# Ajout d'un tag
texte.tag_add( 'orange', lastPos, "%s + %d chars" % ( lastPos, nmbChar.get() ) )
lastPos = "%s + 1 chars" % lastPos
texte.tag_configure( 'orange', foreground = 'dark orange',font=('courier',13))
while 1 :
liste_noms="((\$)([^\$])(\$))"
lastPos = texte.search(liste_noms, index = lastPos, stopindex = 'end', regexp = 1, count = nmbChar )
if lastPos == "" :
break
# Ajout d'un tag
texte.tag_add( 'bleu', lastPos, "%s + %d chars" % ( lastPos, nmbChar.get() ) )
lastPos = "%s + 1 chars" % lastPos
texte.tag_configure( 'bleu', foreground = 'bleu',font=('courier',13))
root = Tk()
texte = Text( root )
texte.grid()
leText = """
\\documentclass[11pt, a4paper]{article}
\\input{C:/Gabriel/latex/perso/enonce.tex}
%\\fenonce
\\begin{document}
\\begin{exercice}
\\begin{enumerate}
\\item%2
\\input{c:/gabriel/ex333.tex} pour voir ce qui si passe.
\\item%4
\\input{c:/gabriel/ex331.tex}
Je tape n'importe quoi du moment que ça fait du texte Une commande $\sqrt{n+1}$ et puis l'ensemble $\S=\{(x,y)\in\Rr^2\}$
\\end{enumerate}
\\end{exercice}
\\end{document}
"""
texte.insert( 'end', leText )
root.bind_all('<KeyPress>',recherche)
root.mainloop() |
Partager