我想在用py-figlet (https://github.com/pwaller/pyfiglet)制作的中间文本上打印。
我的代码如下所示:
from pyfiglet import Figlet
f = Figlet(font='ascii___')
def DrawText(text):
return f.renderText(text)
print(DrawText('text')) <- Center it在输出时,我希望在中间用pyfiglet打印文本。
发布于 2020-11-11 17:17:33
您可以巧妙地将.center()与shutil模块一起使用:
from pyfiglet import Figlet
import shutil
f = Figlet(font='ascii___')
def DrawText(text,center=True):
if center:
print(*[x.center(shutil.get_terminal_size().columns) for x in f.renderText(text).split("\n")],sep="\n")
else:
print(f.renderText(text))
DrawText('text',center=True)发布于 2021-02-08 17:42:43
你可以使用关键字与'auto',‘左侧’,‘中间’,或‘右’
我做了这个:
import pyfiglet
txt = "title"
banner = pyfiglet.figlet_format(txt, font="slant", justify="center")
print(banner)我找不到关于模块的像样的文档。因此,我必须深入研究代码,并为FigletBuilder类构造函数找到关键字。一开始是这样的:
class FigletBuilder(object):
"""
Represent the internals of the build process
"""
def __init__(self, text, font, direction, width, justify):
self.text = list(map(ord, list(text)))
self.direction = direction
self.width = width
self.font = font
self.justify = justifyOptionParser在main()函数(当前的第865行)中也给出了如何使用关键字的指示,以防您想了解更多关于如何使用关键字参数的信息,但不希望滚动大约1000行代码^^。
https://stackoverflow.com/questions/64790990
复制相似问题