包含在 tkinter 文本小部件中的字符串中的标签



Tkinter Text widget 允许使用标签设置文本样式。

text.tag_config('red', foreground='red')
text.insert(END, 'Red text', 'red')

是否可以在字符串文本中包含标签?

伪代码:

text.insert(END, 'This sentence has <red tag>red text</red tag> in it.')

不,这是不可能的。但是,编写在文本小部件中搜索模式并用 tkinter 标签替换它们的代码非常容易。

最新更新