如何在 tkinter 中显示降价格式文本?

How to show markdown format text in tkinter?

python-3.xtkinter GUI 中,我开发了一个具有常规简单 window 的程序。

我想显示一个 markdown 格式字符串保存在一个名为 markdownText 的字符串中 window:

markdownText='_italic_ or **bold**'

期望的输出是:

斜体粗体

有什么解决办法吗?

我只是在寻找类似的解决方案,而且似乎确实没有 Python、TkInter 和 markdown 组合的默认 module/class/library。然而,继续搜索显示了以下选项:

  • Python-Markdown – 此模块能够将 markdown 解析为以下输出格式:Python-Markdown 可以输出 HTML4、XHTML 和 HTML5.
  • TkInter displaying html – As the linked answer indicates, Tkhtml can display html "pretty well", and it has a python wrapper

换句话说,如果您愿意使用转换为 html 的中间步骤,这可能是您在 tkinter GUI 中显示降价字符串的可行途径。