defprint_color_range():""" prints table of formatted text format options """forfginrange(30,38): s1 =''forbginrange(40,48):format=';'.join(['0',str(fg),str(bg)]) s1 +=f'\033[{format}m{format}\033[0m'print(s1) print_color_range() 当然这里只是普通效果的,如果需要加粗,或...
ANSI color formatting for output in terminal。 安装 python3 -m pip install --upgrade termcolor 支持的样式 python -m termcolor 支持的文本属性 示例 import sys from termcolor import colored, cprint text = colored("Hello, World!", "red", attrs=["reverse", "blink"]) print(text) cprint("Hel...
def set_text_color(str_text, style, text_color, background_color): str = str_text style_code = style_dict[style] text_color_code = text_color_dict[text_color] back_color_code = background_color_dict[background_color] print_text = f'\033[{style_code};{text_color_code};{back_colo...
from richimportprint from rich.highlighterimportHighlighterclassRainbowHighlighter(Highlighter):defhighlight(self,text):forindexinrange(len(text)):text.stylize(f"color({randint(16, 255)})",index,index+1)rainbow=RainbowHighlighter()print(rainbow("台下的少年呐,要是你看懂了天外来物,长大了,记得拯救世...
print('\033[27;32;40m这是一行测试字体\033[0m') 具体效果看下面的动图: 需要注意的是具体的效果可能收到使用的终端的限制,目前在CMD中输出并不会被识别,但是在window terminal中是成功的输出以上内容。另外,搜索公众号顶级科技后台回复“API接口”,获取一份惊喜礼包。
(Fore.CYAN, Back.LIGHTBLACK_EX), # 青色灰底,感觉这个效果不错(Fore.YELLOW, Back.RED) # 黄色红底]# 使用不同的颜色组合打印日志信息for foreground_color, background_color in color_combinations:logged_message = f"{foreground_color}{background_color}{log_message}{Style.RESET_ALL}"print(logged_...
print print_textself.reset_color()if __name__ =="__main__": clr =Color() clr.print_red_text('red') clr.print_green_text('green') clr.print_blue_text('blue') clr.print_red_text_with_blue_bg('background') 1. 0x002. Python print color word in Linux terminal...
print(color.white_green('I am white green!')) 输出结果: 3、采用Python的termcolor模块: termcolor是一个python包,可以改变控制台输出的颜色,支持各种terminal(WINDOWS的cmd.exe除外)。 支持下列的文字颜色: grey, red, green, yellow, blue, magenta, cyan, white...
主流terminal对属性的支持如下: 示例代码: 代码语言:javascript 代码运行次数:0 运行 AI代码解释 importsys from termcolorimportcolored,cprint text=colored('Hello, World!','red',attrs=['reverse','blink'])print(text)cprint('Hello, World!','green','on_red')print_red_on_cyan=lambda x:cprint(x...
Colorama 的主要功能:输出一种跨平台的ANSI转义序列,Terminal收到这种特殊的序列后并不直接显示ASCII字符,而是显示指定的颜色。 在大多数常规终端(如 Windows 中的 cmd.exe,Linux/macOS 中的终端)中,控制台输出的文本颜色和样式是通过 ANSI 转义序列实现的。跨平台解决方案colorama库封装了这些 ANSI 转义序列的复杂性...