You should look through the Tags section here: http://effbot.org/tkinterbook/text.htm
You can set this up pretty easily by making a couple of tags (using the tag_config()
method on a Text
widget), let's call them highlight
and unhighlight
:
text.tag_config('highlight', foreground='red')
text.tag_config('unhighlight', foreground='black')
Then, in your Button
callback, attach these tags to the text:
def callback():
# unhighlight everything from the beginning to the end
text.tag_add('unhighlight', 1.0, END)
# insert new text and apply the highlight tag to it
text.insert(END, 'hello world ', 'highlight')