目录
风格字符输出
from rich import print as rprint
st = r'''
________ ___ ___ _________ ___ ___ ________ ________ ________ _________ ___ ___ ___ _______
|\ __ \|\ \ / /|\___ ___\\ \|\ \|\ __ \|\ ___ \ |\ ____\|\___ ___\ |\ \ / /|\ \ |\ ___ \
\ \ \|\ \ \ \/ / ||___ \ \_\ \ \\\ \ \ \|\ \ \ \\ \ \ \ \ \___|\|___ \ \_| \ \ \/ / | \ \ \ \ __/|
\ \ ____\ \ / / \ \ \ \ \ __ \ \ \\\ \ \ \\ \ \ \ \_____ \ \ \ \ \ \ / / \ \ \ \ \ \_|/__
\ \ \___|\/ / / \ \ \ \ \ \ \ \ \ \\\ \ \ \\ \ \ \|____|\ \ \ \ \ \/ / / \ \ \____\ \ \_|\ \
\ \__\ __/ / / \ \__\ \ \__\ \__\ \_______\ \__\\ \__\ ____\_\ \ \ \__\__/ / / \ \_______\ \_______\
\|__||\___/ / \|__| \|__|\|__|\|_______|\|__| \|__| |\_________\ \|__|\___/ / \|_______|\|_______|
\|___|/ \|_________| \|___|/
'''
rprint(f'[green]{st}[/green]')
字符生成器,拿走直接用:http://www.patorjk.com/software/taag/,输入生成后直接复制就可,简单好用,值得拥有
给点颜色瞧瞧
print原生
print("\33[1;32;43m就是这么骚,不容反驳") # 0;32;43 (粗细—0为细,1为粗;字体颜色;背景颜色)
# 上面的例子没有设置结束,设置结束需要在结束处将背景颜色设置为0m print("\33[1;32;43m就是这么骚,不容反驳\33[1;32;0m")
字体颜色和背景颜色设置对照此表
termcolor库
使用一下两个原函数
def colored(text, color=None, on_color=None, attrs=None): def cprint(text, color=None, on_color=None, attrs=None, **kwargs):
colored方法
from termcolor import colored, cprint print(colored('中国', 'blue'), colored('红', 'red')) text = colored('Python骚操作', 'red', attrs=['reverse', 'dark']) print(text)
cprint方法
from termcolor import colored, cprint cprint('Python骚操作', 'green', 'on_yellow') # 生成一个方法函数方便直接调用 my_print = lambda x: cprint(x, 'white', 'on_green') my_print('print骚操作之一') my_print('print骚操作没有最好,只有更好')
colorama库
样式设置之后对后面的所有输出都产生影响,需要取消时进行重置操作
from colorama import Fore, Back, Style print(Fore.YELLOW + '设置文字字体颜色') print(Back.WHITE + '设置背景颜色', Fore.RED, '背景颜色和字体设置后的结果,受前面最近的一个设置影响') print(Style.BRIGHT + '设置字体样式') print(Style.RESET_ALL, end='') # 重置所有设置 print('重置后的打印结果')