我嘗試了很多事情,試圖讓文本留在它的邊界內,但我找不到方法。以下是我已經嘗試過的。如何使文本適合python curses文本框內?
#!/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()
需要注意的是托馬斯·迪基和我已經基本張貼了同樣的答案,雖然他使用'.derwin'創建一個子窗口,這可能是更好的方法。我有圖片。拋硬幣 :) – larsks