1.顏色定義說明
格式:\033[顯示方式;前景色;背景色m
前景色 背景色 顏色
---------------------------------------
30 40 黑色
31 41 紅色
32 42 綠色
33 43 黃色
34 44 藍色
35 45 紫紅色
36 46 青藍色
37 47 白色
顯示方式 意義
-------------------------
0 終端默認設置
1 高亮顯示
4 使用下划線
5 閃爍
7 反白顯示
8 不可見
前景色:
print("--------前景色----------") print("\033[1;30m 黑顏色\033[0m") print("\033[1;31m 紅顏色\033[0m") print("\033[1;32m 綠顏色\033[0m") print("\033[1;33m 黃顏色\033[0m") print("\033[1;34m 藍顏色\033[0m") print("\033[1;35m 紫顏色\033[0m") print("\033[1;36m 青顏色\033[0m") print("\033[1;37m 白顏色\033[0m") print("\033[1;0m 默認色\033[0m")
背景色:
print("--------背景色----------") print("\033[1;40m 背景黑\033[0m") print("\033[1;41m 背景紅\033[0m") print("\033[1;42m 背景綠\033[0m") print("\033[1;43m 背景黃\033[0m") print("\033[1;44m 背景藍\033[0m") print("\033[1;45m 背景紫\033[0m") print("\033[1;46m 背景青\033[0m") print("\033[1;47m 背景白\033[0m")
函數定義:
def color_green(s): return "\033[32;1m%s\033[0m"% s def color_red(s): return "\033[31;1m%s\033[0m"% s def color_yellow(s): return "\033[33;3m%s\033[0m" % s def color_bule(s): return "\033[36;1m%s\033[0m"% s
使用實例:
username = input(color_green('請輸入用戶名')).strip() password = input(color_green('請輸入用戶名')).strip()