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
| import tkinter
import time
def syntaxe_couleur(event=None):
time.sleep(5)
contents = t.get(1.0, tkinter.END)
coordonnees=t.index(tkinter.INSERT)
t.delete("1.0",tkinter.END)
t.insert("1.0",contents)
t.mark_set(tkinter.INSERT, coordonnees)
t.see(coordonnees)
nmbChar = tkinter.IntVar()
lastPos = "1.0"
while 1 :
liste_noms="[0-9]"
lastPos = t.search(liste_noms, index = lastPos, stopindex = tkinter.END, regexp = 1, count = nmbChar )
if lastPos == "" :
break
t.tag_add( 'commandes', lastPos, "%s + %d chars" % ( lastPos, nmbChar.get() ) )
lastPos = "%s + 1 chars" % lastPos
t.tag_configure( 'commandes', foreground = 'red',font=("courier",10))
root=tkinter.Tk()
t=tkinter.Text(root)
t.focus_set()
t.pack()
t.bind('<Control-m>',syntaxe_couleur)
root.mainloop() |
Partager