Python Curses - Printing Ascii Art

淺唱寂寞╮ 提交于 2019-12-12 16:53:45

问题


I have a long multi-line ascii art string that I would like to present to the user using the Python curses module. 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. Any ideas on how this could be accomplished?


回答1:


Loop over the lines, using 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).



来源:https://stackoverflow.com/questions/18521909/python-curses-printing-ascii-art

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!