【问题标题】:colorama/termcolor not returning coloured linescolorama/termcolor 不返回彩色线条
【发布时间】:2019-06-06 17:23:06
【问题描述】:
from colorama import Fore, Back, Style
print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')
print(Style.RESET_ALL)
print('back to normal now')

输出

[31msome红色文字

[42mand 有绿色背景

[2mand indim text

[0米

现在恢复正常

我使用 colorama 库来更改几个单词的字体颜色。不幸的是,它没有返回任何带有各自颜色的行。任何人都可以帮我确定问题吗?在此先感谢

【问题讨论】:

    标签: colors colorama


    【解决方案1】:

    您的代码可以在我的 Linux 机器上运行,但如果您使用的是 Windows,则必须先调用 init()(根据 documentation)。代码如下:

    #!/usr/bin/python3
    from colorama import Fore, Back, Style, init
    
    # only required on Windows
    init()
    
    # print some example lines
    print(Fore.RED + 'some red text')
    print(Back.GREEN + 'and with a green background')
    print(Style.DIM + 'and in dim text')
    print(Style.RESET_ALL)
    print('back to normal now')
    

    【讨论】:

      猜你喜欢
      • 2012-04-08
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多