python在windows下打印彩色字体
来源:互联网 发布:血糖检测数据 编辑:程序博客网 时间:2024/06/05 02:58
#################################################################import ctypesSTD_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_BLUE = 0x10 # background color contains blue.BACKGROUND_GREEN = 0x20 # background color contains green.BACKGROUND_RED = 0x40 # background color contains red.BACKGROUND_INTENSITY = 0x80 # background color is intensified.class Color: ''''' See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/windows_api_reference.asp for information on Windows APIs.''' std_out_handle = ctypes.windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE) def set_cmd_color(self, color, handle=std_out_handle): """(color) -> bit Example: set_cmd_color(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY) """ bool = ctypes.windll.kernel32.SetConsoleTextAttribute(handle, color) return bool def reset_color(self): self.set_cmd_color(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE) def print_red_text(self, print_text): self.set_cmd_color(FOREGROUND_RED | FOREGROUND_INTENSITY) print print_text self.reset_color() def print_green_text(self, print_text): self.set_cmd_color(FOREGROUND_GREEN | FOREGROUND_INTENSITY) print print_text self.reset_color() def print_blue_text(self, print_text): self.set_cmd_color(FOREGROUND_BLUE | FOREGROUND_INTENSITY) print print_text self.reset_color() def print_red_text_with_blue_bg(self, print_text): self.set_cmd_color(FOREGROUND_RED | FOREGROUND_INTENSITY | BACKGROUND_BLUE | BACKGROUND_INTENSITY) print print_text self.reset_color()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')#################################################################
阅读全文
0 0
- python在windows下打印彩色字体
- python在windows的cmd中打印彩色文字
- python在windows的cmd中打印彩色文字
- python在windows的cmd中打印彩色文字
- 打印彩色字体,控制台
- Shell打印彩色字体
- python在cmd中打印彩色文字
- 在Linux环境下实现打印彩色进度条
- printf打印彩色文字,有颜色字体
- logrus在windows的terminal下彩色显示
- 在ubuntu下安装Windows字体
- Python/Perl/Shell 输出彩色字体
- Python终端如何输出彩色字体
- Python终端如何输出彩色字体
- 用python在windows中打印
- windows控制台程序下打印彩色字和获取系统时间的函数
- Perl在终端上输出彩色字体
- 汇编--在屏幕上显示彩色字体
- Ajax实现注册异步校验
- .NET Core全面概览
- .net基础入门
- 如何安装虚拟机
- wordpress设置伪静态及设置后出现问题
- python在windows下打印彩色字体
- 简单的Makefile
- Maven项目中JSP页面无法得到静态资源的解决方法
- ffmpeg VS2013 编译调试
- 切换JDK版本时修改JAVA_HOME环境变量不生效
- 何时考虑阻抗匹配
- Stock(买卖股票)
- Redis集群方案理解及实践
- [shell] -- linux下日志文件的指定起始行和指定行数读取