Is it possible to have Tkinter recognize ANSI escape characters?

Viewed 814

I am trying to print a message in a tk.Text box. The message is the result of a function that returns a search result. I want the message to be formatted in a way where only the header is bold, and the results are normal text:

search_results.append(self.text.BOLD + "Top Tracks for " + artist_found + ":" + self.text.END)
for track in top_tracks['tracks']:
    search_results.append("\t- " + track['name'])
self.search_results_msg = "\n".join(search_results)

Where self.text is an instance of the class below

class Text_Options():
  BOLD = '\033[1m'
  END = '\033[0m'

Tkinter doesn't recognize the ANSI escape characters. Is there anything I could do for ANSI to work? Or what else could I do to achieve what I want. I know there is tk.Font but since I only want to bold the header and leave the rest of the message normal, I don't know if .Font will help me.

1 Answers

Not out of the box. ANSI color control has an example Tcl code to convert them to Tcl markup (basically, replace upon insertion).

Related