Hi!
I was wondering if there is any auto-tag function in Tkinter. I want to make a
simple syntax highlighter, and so far what I've done is bind a function to Key
event and build a string with the registered keys, compare that to a list of
special words and if they match, delete the word from the text and replace it
with a tagged version on the same position. This did not work out very well
because the key event and handlers are fired off on key press, therefore before
the character is actually written in the text itself, resulting in the function
deleting everything before the last letter is printed in the text; this results
always in the last letter of the word remaining on screen (for example
"doctype" = "doctypee").
How can I fix this?
Is there a "KeyUp" event?
Better yet, is there a nicer way to do syntax highlighting?
Please advise.
Here is the bit of code:
self.edit.bind("<Key>", self.parent.key)
...
def key(self,event):
if event.char == " ":
self.word=""
if event.char == event.keysym:
self.word=self.word+event.char
self.match(self.word,"HTML")
def match(self,keyword,lang):
match=False
print keyword
if lang=="HTML":
for item in self.html:
if item==keyword:
match=True
break
if match:
self.tab.editlist[self.tab.nav.index("current")].delete("insert-%s
c" %len(keyword), "insert")
self.tab.editlist[self.tab.nav.index("current")].insert("insert",
keyword, "blue")
Thanks in advance!
Regards,
Andrei Nemes
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss