「安装:」pip install termcolorcprint() 功能相当于print(colored(something))。cprint('sometext','color','on_color',attrs=[])其中:color:文字颜色。可选,grey,red,green,yellow,blue,magenta,cyan,white。on_color:背景色,可选,on_grey,on_red,on_green,on_yellow,on_blue,on_magenta...
(color) def reset_color(): set_cmd_text_color(FOREGROUND_DARKWHITE) def cprint(text, color): set_text_color(color) print(text) reset_color() if __name__ == '__main__': for k in D_COLOR: cprint(f'我是{k}色文字', k) set_text_color('天蓝') print('-' * 30) input('...
color_info ="[\033[36m Info \033[0m]"## 青蓝色 Info user_file="text.txt" print(f"\n{color_err} 请检查 %s 文件是否存在 或 拼写是否正确!!!\n"% user_file ) print(f"\n{color_ok} 请检查 %s 文件是否存在 或 拼写是否正确!!!\n"% user_file ) print(f"\n{color_war} 请检查 ...
color_print('I LOVE YOU', fore='y', back='k') color_print('I HATE YOU', fore='r', back='g', mode='u') 输出:函数体: def color_print(text: str, mode: str = '', fore: str = '', back: str = '') -> None: dict_mode = {'d': '0', 'h': '1', 'nb': '22...
RESET = '\033[0m' # Resets the color to default print(f"{RED}This is red text{RESET}") print(f"{GREEN}This is green text{RESET}") print(f"{YELLOW}This is yellow text{RESET}") print(f"{BLUE}This is blue text{RESET}") print(f"{MAGENTA}This is magenta text{RESET}") print(...
python如何设置print颜色 在Python中,可以使用ANSI转义序列来设置print输出的颜色。以下是一个简单的示例: defprint_colored(text, color_code):""" 参数1:要打印的文本 参数2:颜色代码(例如:\033[31m 为红色,\033[32m 为绿色) """print(f"{color_code}{text}\033[0m")# 示例用法red_color ="\033[...
以上代码中的print_color()函数接受两个参数:text表示要打印的文本,color表示要使用的颜色。我们使用了一个字典来将颜色和对应的 ANSI 转义序列关联起来,然后根据传入的颜色参数来选择合适的 ANSI 转义序列。最后,我们将带颜色的文本和恢复默认样式的转义序列连接起来打印出来。
print(s1) print_color_range() 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 当然这里只是普通效果的,如果需要加粗,或者闪烁,把0改成1或者5 就可以了,你也可以在评论区留言 【python彩色文本图】获取完整的效果。 封装,让彩色打印更好用 ...
color_cmd = "[\033[1;34m Command \033[0m]" ## 蓝色 Command color_info = "[\033[1;36m Info \033[0m]" ## 青蓝色 Info user_file="text.txt" print(f"\n{color_err} 请检查 %s 文件是否存在 或 拼写是否正确!!!\n" % user_file ) ...
以下是一个简单的示例,展示了如何在print函数中使用颜色: def colored_print(text, color_code): print(f"\033[{color_code}m{text}\033[0m") # 使用不同的颜色代码 red_color_code = 31 green_color_code = 32 blue_color_code = 34 colored_print("红色文本", red_color_code) colored_print("...