import
ctypes,sys
STD_INPUT_HANDLE
=
-
10
STD_OUTPUT_HANDLE
=
-
11
STD_ERROR_HANDLE
=
-
12
FOREGROUND_BLACK
=
0x00
FOREGROUND_DARKBLUE
=
0x01
FOREGROUND_DARKGREEN
=
0x02
FOREGROUND_DARKSKYBLUE
=
0x03
FOREGROUND_DARKRED
=
0x04
FOREGROUND_DARKPINK
=
0x05
FOREGROUND_DARKYELLOW
=
0x06
FOREGROUND_DARKWHITE
=
0x07
FOREGROUND_DARKGRAY
=
0x08
FOREGROUND_BLUE
=
0x09
FOREGROUND_GREEN
=
0x0a
FOREGROUND_SKYBLUE
=
0x0b
FOREGROUND_RED
=
0x0c
FOREGROUND_PINK
=
0x0d
FOREGROUND_YELLOW
=
0x0e
FOREGROUND_WHITE
=
0x0f
BACKGROUND_BLUE
=
0x10
BACKGROUND_GREEN
=
0x20
BACKGROUND_DARKSKYBLUE
=
0x30
BACKGROUND_DARKRED
=
0x40
BACKGROUND_DARKPINK
=
0x50
BACKGROUND_DARKYELLOW
=
0x60
BACKGROUND_DARKWHITE
=
0x70
BACKGROUND_DARKGRAY
=
0x80
BACKGROUND_BLUE
=
0x90
BACKGROUND_GREEN
=
0xa0
BACKGROUND_SKYBLUE
=
0xb0
BACKGROUND_RED
=
0xc0
BACKGROUND_PINK
=
0xd0
BACKGROUND_YELLOW
=
0xe0
BACKGROUND_WHITE
=
0xf0
std_out_handle
=
ctypes.windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
def
set_cmd_text_color(color, handle
=
std_out_handle):
Bool
=
ctypes.windll.kernel32.SetConsoleTextAttribute(handle, color)
return
Bool
def
resetColor():
set_cmd_text_color(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
def
printDarkBlue(mess):
set_cmd_text_color(FOREGROUND_DARKBLUE)
sys.stdout.write(mess)
resetColor()
def
printDarkGreen(mess):
set_cmd_text_color(FOREGROUND_DARKGREEN)
sys.stdout.write(mess)
resetColor()
def
printDarkSkyBlue(mess):
set_cmd_text_color(FOREGROUND_DARKSKYBLUE)
sys.stdout.write(mess)
resetColor()
def
printDarkRed(mess):
set_cmd_text_color(FOREGROUND_DARKRED)
sys.stdout.write(mess)
resetColor()
def
printDarkPink(mess):
set_cmd_text_color(FOREGROUND_DARKPINK)
sys.stdout.write(mess)
resetColor()
def
printDarkYellow(mess):
set_cmd_text_color(FOREGROUND_DARKYELLOW)
sys.stdout.write(mess)
resetColor()
def
printDarkWhite(mess):
set_cmd_text_color(FOREGROUND_DARKWHITE)
sys.stdout.write(mess)
resetColor()
def
printDarkGray(mess):
set_cmd_text_color(FOREGROUND_DARKGRAY)
sys.stdout.write(mess)
resetColor()
def
printBlue(mess):
set_cmd_text_color(FOREGROUND_BLUE)
sys.stdout.write(mess)
resetColor()
def
printGreen(mess):
set_cmd_text_color(FOREGROUND_GREEN)
sys.stdout.write(mess)
resetColor()
def
printSkyBlue(mess):
set_cmd_text_color(FOREGROUND_SKYBLUE)
sys.stdout.write(mess)
resetColor()
def
printRed(mess):
set_cmd_text_color(FOREGROUND_RED)
sys.stdout.write(mess)
resetColor()
def
printPink(mess):
set_cmd_text_color(FOREGROUND_PINK)
sys.stdout.write(mess)
resetColor()
def
printYellow(mess):
set_cmd_text_color(FOREGROUND_YELLOW)
sys.stdout.write(mess)
resetColor()
def
printWhite(mess):
set_cmd_text_color(FOREGROUND_WHITE)
sys.stdout.write(mess)
resetColor()
def
printWhiteBlack(mess):
set_cmd_text_color(FOREGROUND_BLACK | BACKGROUND_WHITE)
sys.stdout.write(mess)
resetColor()
def
printWhiteBlack_2(mess):
set_cmd_text_color(
0xf0
)
sys.stdout.write(mess)
resetColor()
def
printYellowRed(mess):
set_cmd_text_color(BACKGROUND_YELLOW | FOREGROUND_RED)
sys.stdout.write(mess)
resetColor()
if
__name__
=
=
'__main__'
:
print
printDarkBlue(u
'printDarkBlue:暗蓝色文字
'
.encode(
'gb2312'
))
printDarkGreen(u
'printDarkGreen:暗绿色文字
'
.encode(
'gb2312'
))
printDarkSkyBlue(u
'printDarkSkyBlue:暗天蓝色文字
'
.encode(
'gb2312'
))
printDarkRed(u
'printDarkRed:暗红色文字
'
.encode(
'gb2312'
))
printDarkPink(u
'printDarkPink:暗粉红色文字
'
.encode(
'gb2312'
))
printDarkYellow(u
'printDarkYellow:暗黄色文字
'
.encode(
'gb2312'
))
printDarkWhite(u
'printDarkWhite:暗白色文字
'
.encode(
'gb2312'
))
printDarkGray(u
'printDarkGray:暗灰色文字
'
.encode(
'gb2312'
))
printBlue(u
'printBlue:蓝色文字
'
.encode(
'gb2312'
))
printGreen(u
'printGreen:绿色文字
'
.encode(
'gb2312'
))
printSkyBlue(u
'printSkyBlue:天蓝色文字
'
.encode(
'gb2312'
))
printRed(u
'printRed:红色文字
'
.encode(
'gb2312'
))
printPink(u
'printPink:粉红色文字
'
.encode(
'gb2312'
))
printYellow(u
'printYellow:黄色文字
'
.encode(
'gb2312'
))
printWhite(u
'printWhite:白色文字
'
.encode(
'gb2312'
))
printWhiteBlack(u
'printWhiteBlack:白底黑字输出
'
.encode(
'gb2312'
))
printWhiteBlack_2(u
'printWhiteBlack_2:白底黑字输出(直接传入16进制参数)
'
.encode(
'gb2312'
))
printYellowRed(u
'printYellowRed:黄底红字输出
'
.encode(
'gb2312'
))