python实现控制台输出彩色字体
2020-04-06 12:06
871 查看
python控制台输出彩色字体,供大家参考,具体内容如下
import ctypes, sys STD_INPUT_HANDLE = -10 STD_OUTPUT_HANDLE = -11 STD_ERROR_HANDLE = -12 # 字体颜色定义 text colors FOREGROUND_BLUE = 0x09 # blue. FOREGROUND_GREEN = 0x0a # green. FOREGROUND_RED = 0x0c # red. FOREGROUND_YELLOW = 0x0e # yellow. # 背景颜色定义 background colors BACKGROUND_YELLOW = 0xe0 # yellow. # get handle 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 | FOREGROUND_BLUE) # green def printGreen(mess): set_cmd_text_color(FOREGROUND_GREEN) sys.stdout.write(mess + '\n') resetColor() # red def printRed(mess): set_cmd_text_color(FOREGROUND_RED) sys.stdout.write(mess + '\n') resetColor() # yellow def printYellow(mess): set_cmd_text_color(FOREGROUND_YELLOW) sys.stdout.write(mess + '\n') resetColor() # white bkground and black text def printYellowRed(mess): set_cmd_text_color(BACKGROUND_YELLOW | FOREGROUND_RED) sys.stdout.write(mess + '\n') resetColor()
使用
printGreen("你好,世界!")
顺便把图形放出来,供大家使用
replyContent = u'''' _ (\\ _ ___ .-"`"(\\ _.""` `"-. / ` `-._ _.-" `\__ 6 6) `-.__.-' `", / `;-` / , | () / /` | `---`"~``\ | \ | \ \ / / /`, , | | / / "-.| | | /' / / | /,__ | /`\ ljs / /' | / `"'\ ( \ __/ /' | | `\ \ \ \ / | | `\ \ \ `-,/ / | / |-"` `"""^^^ `^^""""` ------------------------------------------------''' printGreen(replyContent)
注意:测试在idea开发工具中打印使用未显示彩色,但在Linux控制台,cmd控制台打均为彩色字体。
以上就是本文的全部内容,希望对大家的学习有所帮助
您可能感兴趣的文章:
相关文章推荐
- python通过colorama模块在控制台输出彩色文字的方法
- Python终端输出打印彩色字体的方法
- python脚本的windows控制台彩色文字输出
- Python终端如何输出彩色字体
- Python3利用print输出带颜色的彩色字体示例代码
- Python终端如何输出彩色字体
- python之终端输出彩色字体
- Python Numpy 控制台完全输出ndarray的实现
- python通过colorama模块在控制台输出彩色文字的方法
- Linux/UNIX下终端和控制台彩色字体的实现
- Python/Perl/Shell 输出彩色字体
- C#.NET编程小技俩输出彩色字体的控制台程序,测试分布式系统时可以用到
- python输出彩色字体
- Python3实现控制台输出斜杠转圈等待效果
- Python终端如何输出彩色字体
- 让你的python输出彩色字体 支持 py3
- javascript中浏览器控制台console.log 输出图片,彩色字体,文字
- 批处理(Batch)控制台显示彩色字体--FindStr实现
- Python/Perl/Shell 输出彩色字体
- 利用正则实现彩色控制台输出