获取与 tkinter 文本小部件关联的所有标签?

Get all tags associated with a tkinter Text widget?

我想知道如何一次获取 Text 小部件中的所有标签 。所以假设这是我的内容:


(假设我每次输入 ("tag", text),我的意思是 text 有标签 tag。 )

("keyword", print) ("string", "Hello world!")
("keyword", print) ("string", "You are"), ("support", raw_input())


现在假设这是每个标签的代码:

self.text.tag_config('keyword', foreground="orange")
self.text.tag_config('operator', foreground="blue")
self.text.tag_config('number', foreground="red")
self.text.tag_config('string', foreground="red")
self.text.tag_config('support', foreground="blue")
self.text.tag_config('comment', foreground="violet")
self.text.tag_config('error', background="red")
self.text.tag_config('warning', background="yellow")

现在,是否有任何函数/常量可以仅获取当前在我的字符串中的标签?它会报告 ['keyword', 'string', 'support'].

(注意:大部分我只是想知道这个,因为我很好奇。如果没有,这不像是世界末日。:P)

注意:第二个代码块是在 Python 中编写的,我希望在 Python 中得到答案。 :)

来自my favorite tkinter reference

.tag_names(index=None)

If you pass an index argument, this method returns a sequence of all the tag names that are associated with the character after that index. If you pass no argument, you get a sequence of all the tag names defined in the text widget.

.tag_ranges(tagName) 列出使用特定标签的索引。