【发布时间】:2019-05-02 16:38:39
【问题描述】:
所以我想做一个文本编辑器,但我一直卡在这部分,我想让它实时改变某个输入的单词的颜色,例如:假设我输入 print 我希望它自动将前景色从默认的黑色更改为蓝色。我真的不知道您是否必须使用 tag_configure 来执行此操作,但如果可以,请有人帮我解决,谢谢。
代码:
from tkinter import *
root = Tk()
text = Text(root)
text.grid(row=0)
def Event(event):
text.tag_configure("print", foreground="blue")
#This is a KeyBind to trigger the Function: Event
root.bind("<Return>", Event)
root.mainloop()
【问题讨论】:
-
首先
Event已经是一个python tkinter类了。 -
tag_configure仅用于配置标签,但您必须将标签分配给文本中的单词以更改其颜色。
标签: python-3.x windows tkinter