windows下python输出彩色文字(python3)

本文介绍了在Windows上使用Python3实现彩色文字输出的方法,包括代码示例、制作过程和使用步骤。推荐使用Visual Studio Code编辑器,其强大的函数提示功能能提供便利。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

python输出彩色文字

前言

这篇文章更多是转载,原文:

https://blog.csdn.net/u010467784/article/details/78249607

这里给先记录一下(termcolor和其他的在win上都用不了,目前只发现这个能完美运行),希望大家少走弯路,

代码部分

import ctypes

# 【强调】 有蓝色背景色
# 7 = >默认值
# 0 = >黑色
# 1 =蓝
# 2 = >绿色
# 3 = >水
# 4 = >红色
# 5 = >紫色-purple
# 6 = >黄-yellow
# 7 = >白色-white
# 8 = >灰色-grey
# 9 = >淡蓝色-Light blue  【与 蓝色 无异】
# 10 = >【强调】灰-Light grey
# 11 = >【强调】蓝-Light blue
# 12 = >【强调】绿-Light green
# 13 = >【强调】水-Light water
# 14 = >【强调】红-Light red
# 15 = >白-white
STD_INPUT_HANDLE = -10
STD_OUTPUT_HANDLE= -11
STD_ERROR_HANDLE = -12

FOREGROUND_BLACK = 0x0
FOREGROUND_BLUE = 0x01  # text color contains blue.
FOREGROUND_GREEN = 0x02  # text color contains green.
FOREGROUND_WATER = 0x03  # text color contains water.
FOREGROUND_RED = 0x04  # text color contains red.
FOREGROUND_PURPLE = 0x05  # text color contains purple.
FOREGROUND_YELLOW = 0x06  # text color contains yellow.
FOREGROUND_WHITE = 0x07  # text color contains white.
FOREGROUND_GREY = 0x08  # text color contains grey.
FOREGROUND_LIGHTGREY = 0x10  # text color contains light grey.
FOREGROUND_LIGHTBLUE = 0x11  # text color contains light blue.
FOREGROUND_LIGHTGREEN = 0x12  # text color contains light green.
FOREGROUND_LIGHTWATER = 0x13  # text color contains light water.
FOREGROUND_LIGHTRED 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值