簡體   English   中英

如何在 windows cmd 中打印彩色 pyfiglet 文本

[英]How can I print colored pyfiglet text in windows cmd

您好,所以我正在使用 Python 並且我想在使用 figlet_format 時用顏色打印出程序的名稱,所以我在 vscode 中運行良好,但是當我嘗試在 cmd 中運行文件時,它會打印:

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

[0m

打印它在 vscode 中打印的內容:

在此處輸入圖像描述

所以我想知道在使用 pyfiglet 時是否有辦法在 cmd 中打印顏色,這是我的代碼:

from termcolor import colored
from pyfiglet import figlet_format

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

你也可以試試這個新庫Printy剛剛發布了 1.2.0 版作為跨平台庫。

看看:在 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")

在此處輸入圖像描述

在 Windows 上,您需要安裝Colorama

使 ANSI 轉義字符序列(用於生成彩色終端文本和 cursor 定位)在 MS Windows 下工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM