# -*- coding: UTF-8 -*-
from Tkinter import *
import re
def fn(event):
print event.__dict__
#Как здесь определить имя нажатого тега?
def addTag(tag,start,end):
txt.tag_add(tag,'1.0+%dc'%start,'1.0+%dc'%end)
txt.tag_config(tag, background='yellow', foreground='blue')
txt.tag_bind(tag, '<Double-1>', fn)
tk = Tk()
txt = Text(tk,height=5,width=20,font='Arial 12',wrap=NONE)
txt.pack()
s='''#Line text ##1##
#Line ##text## 2
#Line text ##3##'''
txt.insert(END, s)
text = txt.get(1.0, 'end')
i=0
for mo in re.finditer(r"\#{2}.*?\#{2}", text):
addTag(i, mo.start(), mo.end())
i+=1
tk.mainloop()
1.Обязательно ли здесь всем тегам иметь разное имя?
2.Можно ли немного оптимизировать здесь алгоритм создания тегов? Или и так сойдет?