[Tkinter-discuss] syntax highlighting
teh_sh_meister at yahoo.com
Sat May 21 13:46:07 CEST 2011
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?
Here is the bit of code:
if event.char == " ":
if event.char == event.keysym:
for item in self.html:
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!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tkinter-discuss