python 在终端花样打印 rich

上代码:


from rich import print
from rich.panel import Panel
from rich.console import Console
from rich.text import Text
from rich.progress import track
import time


# 打印文字
def print_box(x, title=None):
    console = Console()
    with console.capture() as capture:
        console.print(x)
    str_output = capture.get()
    text = Text.from_ansi(str_output)
    print(Panel(text, title=title, padding=2))
    for _ in track(range(50)):
        time.sleep(0.1)


if __name__ == '__main__':
    print_box('您输的密码错了', title='密码检测')

输出结果:

image

posted @ 2023-01-30 16:01  Tarzen  阅读(179)  评论(0)    收藏  举报