Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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?

like image 642
Monkeyanator Avatar asked Aug 11 '26 06:08

Monkeyanator


1 Answers

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).

like image 63
Martijn Pieters Avatar answered Aug 13 '26 02:08

Martijn Pieters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!