程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Print print display color in Python

編輯:Python

Format of display color :

\033 [ Display mode ; The foreground ; Background color m … [\ 033 [0m]

notes :’;' Three parameters before and after : Display mode , The foreground , Background color is an optional parameter , You can write only one or two of them ; Because the values representing the different meanings of the three parameters are unique without repetition , So there is no fixed requirement for the writing order of the three parameters , The system can recognize ;
It is recommended to write according to the default format specification

The character color of terminal is controlled by escape sequence , It is the system display function in text mode , It has nothing to do with the specific language . The escape sequence is based on ESC start , The box \033 To complete (ESC Of ASCII The code is expressed in decimal 27, It's in octal 033).

Display color parameters :

Display mode effect The foreground Background color Color description 0 Terminal default settings 3040 black 1 Highlight 3141 Red 4 Use underline 3242 green 5 flashing 3343 yellow 7 On the contrary 3444 Blue 8 invisible 3545 Purplish red 22 Not highlighted 3646 Blue 24 To underline 3747 white 25 To flash 27 Non negative display 28 so

example :

# According to their own needs , Encapsulate the commonly used , You can call it directly when you use it 
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
print(bcolors.HEADER + " Warning color font ?" +bcolors.ENDC)
print('This is a \033[1;35m test \033[0m!')
print('This is a \033[1;32;43m test \033[0m!')
print('\033[1;33;44mThis is a test !\033[0m')

design sketch :

This article is reprinted to :https://blog.csdn.net/qq_34857250/article/details/79673698
author : Mr-Liuqx

Recommended for you :

  • Python It's a deep and shallow copy
  • You don't know Python in global、nonlocal What's up
  • PyCharm-Professional Perfect installation , Permanent use

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved