[Tkinter-discuss] Text() highlight

Michael Lange klappnase at web.de
Tue Aug 26 10:34:21 CEST 2014

On Mon, 25 Aug 2014 14:15:59 +0000
Vasilis Vlachoudis <Vasilis.Vlachoudis at cern.ch> wrote:

> Hi all,
> I am trying to implement a small g-code editor and real time viewer in
> tkinter. I am using the Text() widget as an editor, but I have troubles
> in highlighting the text during editing. Its slow when editing big
> files.

I don't have much experience with the text widget's advanced
capabilities, so I can just give a general hint on how to speed up
repeating tasks in Tkinter.
In my experience calls to Python commands are usually fast enough, the
bottleneck is the calls to Tk, though I am not sure if this is because Tk
is slow in itself or if it is the mechanism of the Tcl interpreter that
is somehow "embedded" into Python that makes things slow.
So as a rule of thumb I suggest that if you want to speed up things I
would try to eliminate as many of the calls to Tkinter widgets from the
repeating routine as possible.
If you want to track down which of these calls are particularly time
expensive sometimes it proved useful to add some calls to time.time() to
measure the duration a particular command took.
So my suggestion is to see, if you can store some of the information
about the tags that you query in your highlight() routine again and again
e.g. with the text widgets search() or compare() methods in a python list
or dictionary and access the information from there. This might
complicate parts of the code but will probably result in a remarkable
speed-up of your routine.



.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Kirk to Enterprise -- beam down yeoman Rand and a six-pack.

More information about the Tkinter-discuss mailing list