简体   繁体   English

Python诅咒-印刷Ascii Art

[英]Python Curses - Printing Ascii Art

I have a long multi-line ascii art string that I would like to present to the user using the Python curses module. 我有一条长的多行ascii艺术字符串,我想使用Python curses模块呈现给用户。 I am a bit confused as to approaching this, as the only method to print a string in curses is addstr(y,x,string), which only prints to one line. 我对此有点困惑,因为在curses中打印字符串的唯一方法是addstr(y,x,string),它只能打印到一行。 Any ideas on how this could be accomplished? 关于如何实现的任何想法?

Loop over the lines, using str.splitlines() : 使用str.splitlines()遍历各行:

for y, line in enumerate(ascii_art.splitlines(), 2):
    w.addstr(y, 2, line)

This uses enumerate() to keep track of the y position, putting the whole ascii-art string on the screen starting at position (2, 2). 它使用enumerate()跟踪y位置,将整个ascii-art字符串从位置(2,2)开始放在屏幕上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM