根据 http://www.tkdocs.com/tutorial/text.html#more , 在 Tk/Tcl 中,可以在文本小部件中嵌入“省略”文本,即不显示的文本。这听起来很有用。这个功能在 Python 中可用吗?如果有,API 是什么?
请您参考如下方法:
下面的示例使用 tags 生成一个 Text 小部件,其中省略了文本:
import tkinter as tk
root = tk.Tk()
text = tk.Text(root)
text.pack()
text.tag_config('mytag', elide=True)
text.insert('end', "This text is non-elided.")
text.tag_add('mytag', '1.13', '1.17')
def toggle_elision():
# cget returns string "1" or "0"
if int(text.tag_cget('mytag', 'elide')):
text.tag_config('mytag', elide=False)
else:
text.tag_config('mytag', elide=True)
tk.Button(root, text="Toggle", command=toggle_elision).pack()
root.mainloop()
