How to make text fit inside a python curses textbox?

Viewed 4010

I've tried many things attempting to make the text stay inside its borders but I can't find a way. Below is what I've already tried.

#!/usr/bin/env python

import curses
import textwrap

screen = curses.initscr()
screen.immedok(True)

try:
    screen.border(0)

    box1 = curses.newwin(20, 40, 6, 50)
    box1.immedok(True)
    text = "I want all of this text to stay inside its box. Why does it keep going outside its borders?"
    box1.box()
    box1.addstr(1, 0, textwrap.fill(text, 39))

    #box1.addstr("Hello World of Curses!")

    screen.getch()

finally:
    curses.endwin()
2 Answers
Related