\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).
# 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')
This article is reprinted to :https://blog.csdn.net/qq_34857250/article/details/79673698
author : Mr-Liuqx
Recommended for you :