【问题标题】:How can I print colored pyfiglet text in windows cmd如何在 Windows cmd 中打印彩色 pyfiglet 文本
【发布时间】:2020-04-12 15:11:12
【问题描述】:

您好,我正在使用 Python,我想在使用 figlet_format 时用颜色打印出程序的名称,所以我在 vscode 中可以正常工作,但是当我尝试在 cmd 中运行文件时,它会打印:

[34m _   _      _ _
| | | | ___| | | ___
| |_| |/ _ \ | |/ _ \
|  _  |  __/ | | (_) |
|_| |_|\___|_|_|\___/

[0m

insted 打印它在 vscode 中打印的内容:

所以我想知道是否有办法在使用 pyfiglet 时在 cmd 中打印颜色,这是我的代码:

from termcolor import colored
from pyfiglet import figlet_format

print((colored(figlet_format("Hello"), color="blue")))

【问题讨论】:

标签: python colors termcolor figlet


【解决方案1】:

您也可以试试这个新库Printy 刚刚发布了 1.2.0 版作为跨平台库。

检查一下: Printy on github

它基于标志,所以你可以做类似的事情

from printy import printy

# with global flags, this will apply a bold (B) red (r) color and an underline (U) to the whole text
printy("Hello world", "rBU")

# with inline formats, this will apply a dim(D)
#blue (b) to the word 'Hello' and a striked (S)
#yellow (y) to the word 'world', the rest will remain as the predefined format
printy("this is a [bD]Hello@ [yS]world@ text")

【讨论】:

    【解决方案2】:

    在Windows上,你需要安装Colorama

    使 ANSI 转义字符序列(用于生成彩色终端文本和光标定位)在 MS Windows 下工作。

    【讨论】:

    • 非常感谢,我才弄明白!
    猜你喜欢
    • 2023-04-06
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 2016-03-16
    • 2017-07-17
    • 1970-01-01
    • 2019-03-22
    • 2010-09-22
    相关资源
    最近更新 更多