1def colored(r, g, b, text):
2 return "\033[38;2;{};{};{}m{} \033[38;2;255;255;255m".format(r, g, b, text)
3
4text = 'Hello, World'
5colored_text = colored(255, 0, 0, text)
6print(colored_text)
7
8#or
9
10print(colored(255, 0, 0, 'Hello, World'))
1from colorama import init, Fore, Back, Style
2init()
3
4print("normal")
5print(Fore.LIGHTYELLOW + "yellow" + Fore.RESET)
6print(Back.RED + "red" + Back.RESET)
7print(Fore.YELLOW + Back.RED + "both" + Style.RESET_ALL)
8print("normal again")
9
10
11
12The possible colors are: BLACK, BLUE, CYAN, GREEN, LIGHTBLACK_EX,
13 LIGHTBLUE_EX, LIGHTCYAN_EX, LIGHTGREEN_EX, LIGHTMAGENTA_EX, LIGHTRED_EX,
14 LIGHTWHITE_EX, LIGHTYELLOW_EX, MAGENTA, RED, WHITE, YELLOW
1const (
2 ResetAll = "\033[0m"
3
4 Bold = "\033[1m"
5 Dim = "\033[2m"
6 Underlined = "\033[4m"
7 Blink = "\033[5m"
8 Reverse = "\033[7m"
9 Hidden = "\033[8m"
10
11 ResetBold = "\033[21m"
12 ResetDim = "\033[22m"
13 ResetUnderlined = "\033[24m"
14 ResetBlink = "\033[25m"
15 ResetReverse = "\033[27m"
16 ResetHidden = "\033[28m"
17
18 Default = "\033[39m"
19 Black = "\033[30m"
20 Red = "\033[31m"
21 Green = "\033[32m"
22 Yellow = "\033[33m"
23 Blue = "\033[34m"
24 Magenta = "\033[35m"
25 Cyan = "\033[36m"
26 LightGray = "\033[37m"
27 DarkGray = "\033[90m"
28 LightRed = "\033[91m"
29 LightGreen = "\033[92m"
30 LightYellow = "\033[93m"
31 LightBlue = "\033[94m"
32 LightMagenta = "\033[95m"
33 LightCyan = "\033[96m"
34 White = "\033[97m"
35
36 BackgroundDefault = "\033[49m"
37 BackgroundBlack = "\033[40m"
38 BackgroundRed = "\033[41m"
39 BackgroundGreen = "\033[42m"
40 BackgroundYellow = "\033[43m"
41 BackgroundBlue = "\033[44m"
42 BackgroundMagenta = "\033[45m"
43 BackgroundCyan = "\033[46m"
44 BackgroundLightGray = "\033[47m"
45 BackgroundDarkGray = "\033[100m"
46 BackgroundLightRed = "\033[101m"
47 BackgroundLightGreen = "\033[102m"
48 BackgroundLightYellow = "\033[103m"
49 BackgroundLightBlue = "\033[104m"
50 BackgroundLightMagenta = "\033[105m"
51 BackgroundLightCyan = "\033[106m"
52 BackgroundWhite = "\033[107m"
53)
1print("\033[0;37;40m Normal text\n")
2print("\033[2;37;40m Underlined text\033[0;37;40m \n")
3print("\033[1;37;40m Bright Colour\033[0;37;40m \n")
4print("\033[3;37;40m Negative Colour\033[0;37;40m \n")
5print("\033[5;37;40m Negative Colour\033[0;37;40m\n")
6
7print("\033[1;37;40m \033[2;37:40m TextColour BlackBackground TextColour GreyBackground WhiteText ColouredBackground\033[0;37;40m\n")
8print("\033[1;30;40m Dark Gray \033[0m 1;30;40m \033[0;30;47m Black \033[0m 0;30;47m \033[0;37;41m Black \033[0m 0;37;41m")
9print("\033[1;31;40m Bright Red \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")
10print("\033[1;32;40m Bright Green \033[0m 1;32;40m \033[0;32;47m Green \033[0m 0;32;47m \033[0;37;43m Black \033[0m 0;37;43m")
11print("\033[1;33;40m Yellow \033[0m 1;33;40m \033[0;33;47m Brown \033[0m 0;33;47m \033[0;37;44m Black \033[0m 0;37;44m")
12print("\033[1;34;40m Bright Blue \033[0m 1;34;40m \033[0;34;47m Blue \033[0m 0;34;47m \033[0;37;45m Black \033[0m 0;37;45m")
13print("\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")
14print("\033[1;36;40m Bright 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")
15print("\033[1;37;40m White \033[0m 1;37;40m \033[0;37;40m Light Grey \033[0m 0;37;40m \033[0;37;48m Black \033[0m 0;37;48m")
16
17\n")
18