我已经设置了一个带有标签的文本小部件,它将使用elide隐藏部分信息。它可以正常工作,但我看到性能点击,如果我隐藏与elide的文本大段。我注意到的文本文件大约有53000行,较小的文件影响较小。程序运行良好,我可以滚动和移动窗口中没有问题,直到我隐藏了一段文字。你知道吗
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()
要复制:
获取一些非常大的文本文件(不必是7),并使用上面的代码将它们全部转储到文本小部件中。然后双击带有“==========================================================”的行以最小化该文件中的所有文本。如果最小化最后一个打印的文件,一切正常。如果你把第一个最小化,你会发现在突出显示文本、点击窗口中的任何地方等方面的反应都很慢
当“elide”设置为true时会发生什么导致这种情况?你知道吗
在用pyinstaller创建了一个exe之后,我在不同的机器上测试了pycharm。你知道吗
文本小部件目前正在经历一个完整的重写和广泛的测试。具有更好elide性能的新版本应该在Tcl/tkversion8.7中提供。你知道吗
新版本的公告通常在comp.lang.tcl新闻组中发布。新版本也将在主网站上公布 http://www.tcl.tk/。你知道吗
不幸的是,由于人员和时间的限制,无法估计何时发布。我的预期(猜测)是,将有一个8.6.7错误修复版本,并可能8.7之后。你知道吗
相关问题 更多 >
编程相关推荐