gpt4 book ai didi

python - 控制台颜色 (Windows)

转载 作者:可可西里 更新时间:2023-11-01 10:29:46 26 4
gpt4 key购买 nike

是否可以在 Python for Windows 中打印出不同颜色的东西?我已经启用了 ANSI.sys,但这并不能正常工作。

我希望能够以红色打印一行,然后以绿色打印下一行,等等。

最佳答案

WConio模块应该是完成此操作所需的全部内容。

WConio.textbackground(color) sets the background color without changing the foreground. See below for the color constants.

WConio.textcolor(color) sets the foreground color without changing the background. See below for the color constants.

它引用的常量实际上并没有列在页面上,而是在WConio.py 文件的顶部:

BLACK = 0
BLUE = 1
GREEN = 2
CYAN = 3
RED = 4
MAGENTA = 5
BROWN = 6
LIGHTGRAY = LIGHTGREY = 7
DARKGRAY = DARKGREY = 8
LIGHTBLUE = 9
LIGHTGREEN = 10
LIGHTCYAN = 11
LIGHTRED = 12
LIGHTMAGENTA = 13
YELLOW = 14
WHITE = 15

因此,将文本前景色设置为红色的完整调用为:

WConio.textcolor(WConio.RED)

关于python - 控制台颜色 (Windows),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3508906/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com