How To Change Print Color In Python
To make some of your text more readable, you can apply ANSI escape codes to alter the colour of the text output in your python plan. A good utilise case for this is to to highlight errors.
The escape codes are entered right into the print argument.
print("\033[1;32;40m Vivid Green \n")
The above ANSI escape code will prepare the text colour to bright green. The format is;
\033[ Escape code, this is ever the same
1 = Style, 1 for normal.
32 = Text colour, 32 for brilliant green.
40m = Background colour, forty is for black.
This table shows some of the bachelor formats;
Text color | Code | Text manner | Code | Groundwork colour | Code |
---|---|---|---|---|---|
Blackness | 30 | No consequence | 0 | Black | xl |
Red | 31 | Bold | i | Blood-red | 41 |
Greenish | 32 | Underline | two | Green | 42 |
Yellow | 33 | Negative1 | 3 | Yellowish | 43 |
Blue | 34 | Negative2 | v | Bluish | 44 |
Purple | 35 | Purple | 45 | ||
Cyan | 36 | Cyan | 46 | ||
White | 37 | White | 47 |
Here is the lawmaking used to create the coloured text in the title image;
print("\033[0;37;40m Normal text\due north") print("\033[two;37;40m Underlined text\033[0;37;40m \n") print("\033[i;37;40m Vivid Colour\033[0;37;40m \n") print("\033[3;37;40m Negative Color\033[0;37;40m \north") impress("\033[5;37;40m Negative Colour\033[0;37;40m\n") print("\033[1;37;40m \033[2;37:40m TextColour BlackBackground TextColour GreyBackground WhiteText ColouredBackground\033[0;37;40m\n") impress("\033[1;30;40m Nighttime Gray \033[0m ane;30;40m \033[0;thirty;47m Black \033[0m 0;30;47m \033[0;37;41m Blackness \033[0m 0;37;41m") print("\033[1;31;40m Bright Carmine \033[0m 1;31;40m \033[0;31;47m Red \033[0m 0;31;47m \033[0;37;42m Black \033[0m 0;37;42m") print("\033[1;32;40m Vivid Green \033[0m 1;32;40m \033[0;32;47m Dark-green \033[0m 0;32;47m \033[0;37;43m Black \033[0m 0;37;43m") print("\033[one;33;40m Xanthous \033[0m i;33;40m \033[0;33;47m Brown \033[0m 0;33;47m \033[0;37;44m Black \033[0m 0;37;44m") print("\033[one;34;40m Bright Blue \033[0m 1;34;40m \033[0;34;47m Blueish \033[0m 0;34;47m \033[0;37;45m Black \033[0m 0;37;45m") print("\033[1;35;40m Bright Magenta \033[0m 1;35;40m \033[0;35;47m Magenta \033[0m 0;35;47m \033[0;37;46m Black \033[0m 0;37;46m") print("\033[1;36;40m Brilliant Cyan \033[0m 1;36;40m \033[0;36;47m Cyan \033[0m 0;36;47m \033[0;37;47m Black \033[0m 0;37;47m") print("\033[one;37;40m White \033[0m 1;37;40m \033[0;37;40m Lite Gray \033[0m 0;37;40m \033[0;37;48m Black \033[0m 0;37;48m") \north")
Blip, blop, bloop...
Source: https://ozzmaker.com/add-colour-to-text-in-python/#:~:text=To%20make%20some%20of%20your,right%20into%20the%20print%20statement.&text=1%20%3D%20Style%2C%201%20for%20normal.
Posted by: poguefaciet.blogspot.com
0 Response to "How To Change Print Color In Python"
Post a Comment