是否可以让 Tkinter 识别 ANSI 转义字符? [英] Is it possible to have Tkinter recognize ANSI escape characters?

查看:43
本文介绍了是否可以让 Tkinter 识别 ANSI 转义字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 tk.Text 框中打印一条消息.该消息是返回搜索结果的函数的结果.我希望消息的格式设置为只有标题为粗体,结果为普通文本:

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)

其中 self.text 是下面类的一个实例

Where self.text is an instance of the class below

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

Tkinter 无法识别 ANSI 转义字符.我可以为 ANSI 做些什么吗?或者我还能做什么来实现我想要的.我知道有 tk.Font 但由于我只想加粗标题并使其余消息正常,我不知道 .Font 是否会帮助我.

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.

推荐答案

不是开箱即用的.ANSI 颜色控件 有一个示例 Tcl 代码将它们转换为 Tcl 标记(基本上,插入时替换).

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

这篇关于是否可以让 Tkinter 识别 ANSI 转义字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆