问题
I've setup a Text widget with tags that will hide sections of information using elide. It works fine with normal entries but im seeing performance hits if I hide large sections of text with elide. The text files i've noticed this with are ~53,000 lines and the impact is less with smaller files. The program runs fine and im able to scroll and move around in the window without a problem until I hide I section of text.
from tkinter import *
master = Tk()
file = 'file\path'
file1 = 'file\path'
file2 = 'file\path'
file3 = 'file\path'
file4 = 'file\path'
file5 = 'file\path'
file6 = 'file\path'
file7 = 'file\path'
list = [file, file1, file2, file3, file4, file5, file6, file7]
def _toggle_visibility(event, widg):
global txt
try:
block_start, block_end = _get_block("insert", widg)
except:
return
next_hidden = widg.tag_nextrange("hidden", block_start, block_end)
if next_hidden:
widg.tag_remove("hidden", block_start, block_end)
else:
widg.tag_add("hidden", block_start, block_end)
def _get_block(index, widg):
global txt
'''return indicies after header, to next header or EOF'''
start = widg.index("%s lineend+1c" % index)
next_header = widg.tag_nextrange("header", start)
if next_header:
end = next_header[0]
else:
end = widg.index("end-1c")
return (start, end)
txt = Text(master)
txt.grid()
txt.tag_configure("header", foreground="#9b3e96") # , spacing1=10, spacing3=10)
txt.tag_bind("header", "<Double-1>", lambda event: _toggle_visibility(event, txt))
txt.tag_configure("hidden", elide=True)
for item in list:
with open(item) as f:
h = f.readlines()
txt.insert('end', '==============================================\n ', 'header')
txt.insert('end', h)
master.mainloop()
To replicate:
get a handful of really big text files(doesn't have to be 7) and use the above code to dump them all into a Text widget. Then double click the line with "==============================================" to minimize all the text from that file. If you minimize the last file that has been printed everything works fine. If you minimize the first one you'll start seeing slow response in highlighting text, clicking anywhere in the window, etc.
Whats happening when 'elide' is set to true that causes this?
I've tested this from pycharm and on a different machine after creating an exe with pyinstaller.
回答1:
The text widget is currently undergoing a complete rewrite and extensive testing. The new version, with better elide performance should become available with Tcl/Tk version 8.7.
Announcements of the new version are usually made in the comp.lang.tcl newsgroup. The new version will also be announced on the main website http://www.tcl.tk/.
Unfortunately, due to personnel and time constraints, there's no estimate on when the release(s) will become available. My expectation (guess) is that there will be an 8.6.7 bug fix release, and probably 8.7 after that.
来源:https://stackoverflow.com/questions/43416330/performance-impact-when-hiding-text-with-elide