Python学习笔记之函数print颜色显示

1. print颜色

def demo_print():
    print('\033[30m打印前景色0\033[0m')
    print('\033[31m打印前景色1\033[0m')
    print('\033[32m打印前景色2\033[0m')
    print('\033[33m打印前景色3\033[0m')
    print('\033[34m打印前景色4\033[0m')
    print('\033[35m打印前景色5\033[0m')
    print('\033[36m打印前景色6\033[0m')
    print('\033[37m打印前景色7\033[0m')
    print('\033[40m打印背景色0\033[0m')
    print('\033[41m打印背景色1\033[0m')
    print('\033[42m打印背景色2\033[0m')
    print('\033[43m打印背景色3\033[0m')
    print('\033[44m打印背景色4\033[0m')
    print('\033[45m打印背景色5\033[0m')
    print('\033[46m打印背景色6\033[0m')
    print('\033[47m打印背景色7\033[0m')
    print('\033[0m打印显示方式0\033[0m')
    print('\033[1m打印显示方式1\033[0m')
    print('\033[4m打印显示方式4\033[0m')
    print('\033[5m打印显示方式5\033[0m')
    print('\033[7m打印显示方式7\033[0m')
    print('\033[8m打印显示方式8\033[0m')
    print('\033[0;37;41m综合打印\033[0m')

2. cPrint颜色

def demo_trace():

    from cprint import cprint

    arg = "hello world"

    cprint(arg)  # WHITE
    cprint.ok(arg)  # BLUE
    cprint.info(arg)  # GREEN
    cprint.warn(arg)  # YELLOW
    cprint.err(arg, interrupt=False)  # BROWN
    cprint.fatal(arg, interrupt=False)  # RED

3. print - call

def demo_third():
    import time
    from subprocess import call

    for color in ('a', 'e', 'c'):  # cycles through different colours
        call('cls', shell=True)  # clears the screen
        call('color ' + color, shell=True)
        print('The quick brown fox jumps over the lazy dog.')
        time.sleep(1)

    input("\nPress enter to exit. ")

 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页