-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path控制台输出彩色文字.py
51 lines (41 loc) · 1.04 KB
/
控制台输出彩色文字.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from colorama import init, Fore, Back, Style
def 初级使用():
init(autoreset=True)
print(Style.BRIGHT + Back.BLACK + Fore.RED + "from colorama import init, Fore, Back, Style")
# 简单的变色函数
background_color_dict = {
'BLACK': 40,
'RED': 41,
'GREEN': 42,
'YELLOW': 43,
'BLUE': 44,
'MAGENTA': 45,
'CYAN': 46,
'WHITE': 47
}
text_color_dict = {
'BLACK': 30,
'RED': 31,
'GREEN': 32,
'YELLOW': 33,
'BLUE': 34,
'MAGENTA': 35,
'CYAN': 36,
'WHITE': 37
}
style_dict = {
'normal': 0,
'bold': 1,
'light': 2,
'italicize': 3,
'underline': 4,
'blink': 5
}
def set_text_color(str_text, style, text_color, background_color):
str = str_text
style_code = style_dict[style]
text_color_code = text_color_dict[text_color]
back_color_code = background_color_dict[background_color]
print_text = f'\033[{style_code};{text_color_code};{back_color_code}m{str}\033[0m'
return print_text
print(set_text_color("ceshishuchu", "bold", "RED", "BLACK"))