【问题标题】:Python text color is not working in CMD but it is working in Windows TerminalPython 文本颜色在 CMD 中不起作用,但在 Windows 终端中起作用
【发布时间】:2022-01-25 12:38:40
【问题描述】:

我正在做一个有趣的项目来在控制台中产生颜色。在 Windows 终端中,它工作正常。但是,在 CMD 中并非如此。你能帮帮我吗?

from termcolor import cprint

cprint("Hello World","blue")

input()

Windows 终端:

命令提示符:

谢谢。

【问题讨论】:

  • 请将文本作为文本发布,而不是文本图像。
  • 已更新,请帮忙
  • 我建议你不要使用这样的程序(和大多数天真的库来给你颜色):它只是不检查终端功能,它有硬编码的转义序列(不知道终端是否有任何ECMA-48 的想法)。有各种各样的库做得很好(如此便携,没有天真的猜测)。

标签: python terminal colors


【解决方案1】:

使用 Colorama 使 Termcolor 在 Windows 中工作:

这是我从 :REFERENCE 获得参考的地方

from colorama import init
from termcolor import cprint

init()
#colored() will also work
cprint("Hello World test","cyan")

#hit enter to exit

input()


【讨论】:

    【解决方案2】:

    尝试通过安装colorama 包来修复它:

    pip install colorama
    

    Source.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-27
      • 2018-11-07
      • 1970-01-01
      • 2012-06-30
      相关资源
      最近更新 更多