Python colorama打印没有

2024-04-25 22:21:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我不知道这类问题叫什么,但在这里。 我编写了一个函数,用转义序列将给定的列表显示在中间。在控制台里一切正常。但当我把程序作为文件运行时,它就不起作用了。你知道吗

from colorama import *
import time
from blessings import Terminal
init(autoreset=False)
t=Terminal()
l1=["Such middle. Much center.","I <3 Python","Unicorn power all over the world"]

def strcenter(l):
    strc=[]
    e=int(int(int(t.height)-int(len(l)))/2)+1
    for i in range(1,e):
        strc.append("\n")
    if (e % 2 == 0):
        for p in l:
            pc=p.center(t.width," ")
            strc.append(pc+"\n")
    else:
        for p in l:
            pc=p.center(t.width," ")
            strc.append(pc+"\n")
        strc.append(" ".center(t.width," ")+"\n")
    for i in range(1,e-2):
        strc.append("\n")
    return "".join(strc)


print Style.BRIGHT+Back.WHITE+Fore.BLUE+strcenter(l1)+Style.RESET_ALL
time.sleep(5)

谢谢。你知道吗


Tags: infromimportl1fortimerangewidth
1条回答
网友
1楼 · 发布于 2024-04-25 22:21:05

作为per the docscolorama只在终端中工作,而不是在空闲运行时工作(可能是您所说的将程序作为文件运行的意思)。这是经过设计的,不能让colorama在空闲内存中工作。你知道吗

相关问题 更多 >

    热门问题