【问题标题】:Text Blink(when printing) in Python 2.7Python 2.7 中的文本闪烁(打印时)
【发布时间】:2018-11-01 07:47:50
【问题描述】:

我正在尝试让 python 中的文本闪烁。我找到了这个方法:

from termcolor import colored, cprint
cprint('\nJames Everleigh', 'red', attrs=['blink'])

但是当我编译它时,我得到了一些奇怪的文本:

""[5m[31m
James Everleigh[0m ""

我需要使用什么来获得所需的输出?

【问题讨论】:

标签: python text


【解决方案1】:

如果你使用的是 windows powershell,你需要 pip coloramaimport init from colorama 并像这样运行它:

from colorama import init
from termcolor import colored
init()
print(colored("text","red"))

【讨论】:

    【解决方案2】:

    [5m[31m 和 [0m 是ANSI escape codes 用于格式和颜色。您必须启用终端来解释它们。

    【讨论】:

    • @TibiGhimbas 你用的是什么终端模拟器?在许多终端中,闪烁只是明亮或粗体文本。
    猜你喜欢
    • 1970-01-01
    • 2012-03-08
    • 2017-03-08
    • 1970-01-01
    • 2020-02-29
    • 2012-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多