bg=6,7# 设置背景色、前景色color=fg+bg<<4ctypes.windll.kernel32.SetConsoleTextAttribute(handle,co...
2,SetConsoleTextAttribute() 其作用是在控制台中设置输入或者输出文本的文字颜色和背景颜色。其函数声明如下: 1 2 3 4 BOOL SetConsoleTextAttribute( HANDLE hConsoleOutput,// console 屏幕缓冲区的句柄 WORD wAttributes// 文本及背景的颜色 ); 文本与背景的颜色设置可以参考Windows上“color/?” 命令的说明。颜...
std_out_handle = ctypes.windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE) def set_cmd_text_color(color, handle=std_out_handle): Bool = ctypes.windll.kernel32.SetConsoleTextAttribute(handle, color) return Bool #reset white def resetColor(): set_cmd_text_color(FOREGROUND_RED | FOREGROUND_GREEN ...
STD_INPUT_HANDLE= -10STD_OUTPUT_HANDLE= -11STD_ERROR_HANDLE= -12FOREGROUND_BLACK= 0x0FOREGROUND_BLUE= 0x01#text color contains blue.FOREGROUND_GREEN= 0x02#text color contains green.FOREGROUND_RED = 0x04#text color contains red.FOREGROUND_INTENSITY = 0x08#text color is intensified.BACKGROUND_...
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"]) ...
GetStdHandle(STD_OUTPUT_HANDLE) # 设置字体颜色的代码 def set_cmd_color(self, color, handle=std_out_handle): bool = ctypes.windll.kernel32.SetConsoleTextAttribute(handle, color) return bool # 颜色重置 def reset_color(self): self.set_cmd_color(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_...
ANSII Color formatting for output in terminal. 利用termcolor查看log,进行代码调试,清晰标出自己想要查看的部分。 1. 属性配置 ATTRIBUTES = dict(list(zip(['bold','dark','','underline','blink','','reverse','concealed'],list(range(1, 9)))del ATTRIBUTES['']HIGHLIGHTS = dict(list(zip(['on_...
std_out_handle = ctypes.windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE) def set_cmd_text_color(color, handle=std_out_handle): Bool = ctypes.windll.kernel32.SetConsoleTextAttribute(handle, color) return Bool 1. 2. 3. 4. 5. 6.
std_out_handle=ctypes.windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)defset_cmd_text_color(color,handle=std_out_handle):Bool=ctypes.windll.kernel32.SetConsoleTextAttribute(handle,color)returnBool #reset white defresetColor():set_cmd_text_color(FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE)### ...
defget_color_name(r,g,b,csv_df):# 基于给定的R,G,B和颜色表,匹配与所取点RGB数值最接近的颜色。 min_diff=10000color=[""foriinrange(6)]foriinrange(len(csv_df)):d=abs(r-int(csv_df.loc[i,"R"]))+abs(g-int(csv_df.loc[i,"G"]))+abs(b-int(csv_df.loc[i,"B"]))ifd<=...