Python 3.x 在Python/Curses中设置文本格式以适应方框

Python 3.x 在Python/Curses中设置文本格式以适应方框,python-3.x,python-curses,Python 3.x,Python Curses,请建议某人如何修复诅咒中的文本面板 我的坏结果 ----- Panel ------ | Lorem ipsum dol or sit amet consec tet uer metus nec eu C urabitur elei fen. | | | ------------------ 我想要结果 ----- Panel ------ | Lorem ipsum do | | lor sit amet | | consecte

请建议某人如何修复诅咒中的文本面板

我的坏结果

----- Panel ------
| Lorem ipsum dol
or sit amet consec
tet uer metus nec 
eu C urabitur elei
fen.             |
|                |
------------------
我想要结果

----- Panel ------
| Lorem ipsum do | 
| lor sit amet   |
| consectet uer  |
| metus nec eu C |
| urabitur       |
| eleifen.       |
------------------
试试这个:

from __future__ import division #You don't need this in Python3
from math import *
string = "0123456789012345678901234567890123456789"
columns = 5
rows = int(ceil(len(string)/columns))
for row in range(1,rows+1):
    panel.addstr(row,1,string[(row*columns)-columns:row*columns])
其结果是:

01234
56789
01234
56789
01234
56789
01234
56789
下面是一个
python诅咒
示例:

from __future__ import division  #You don't need this in Python3
import curses
from math import *

screen = curses.initscr()
curses.noecho()
curses.cbreak()
curses.start_color()
screen.keypad( 1 )
curses.init_pair(1,curses.COLOR_BLACK, curses.COLOR_CYAN)
highlightText = curses.color_pair( 1 )
normalText = curses.A_NORMAL
screen.border( 0 )
curses.curs_set( 0 )
columns = 5
string = "Lorem ipsum dolor sit amet consectetuer metus nec eu C urabitur eleifen."
screen.addstr(1,1,string)
screen.addstr(20,1,"Press ESC to EXIT")
screen.refresh()
rows = int(ceil(len(string)/columns))
box = curses.newwin(rows + 2, columns + 2, 3, 1)
box.box()
for row in range(1,rows+1):
    box.addstr(row,1,string[(row*columns)-columns:(row*columns)])
    box.refresh()

x = screen.getch()
while x != 27:
    x = screen.getch()
curses.endwin()
exit()

试试这个:

from __future__ import division #You don't need this in Python3
from math import *
string = "0123456789012345678901234567890123456789"
columns = 5
rows = int(ceil(len(string)/columns))
for row in range(1,rows+1):
    panel.addstr(row,1,string[(row*columns)-columns:row*columns])
其结果是:

01234
56789
01234
56789
01234
56789
01234
56789
下面是一个
python诅咒
示例:

from __future__ import division  #You don't need this in Python3
import curses
from math import *

screen = curses.initscr()
curses.noecho()
curses.cbreak()
curses.start_color()
screen.keypad( 1 )
curses.init_pair(1,curses.COLOR_BLACK, curses.COLOR_CYAN)
highlightText = curses.color_pair( 1 )
normalText = curses.A_NORMAL
screen.border( 0 )
curses.curs_set( 0 )
columns = 5
string = "Lorem ipsum dolor sit amet consectetuer metus nec eu C urabitur eleifen."
screen.addstr(1,1,string)
screen.addstr(20,1,"Press ESC to EXIT")
screen.refresh()
rows = int(ceil(len(string)/columns))
box = curses.newwin(rows + 2, columns + 2, 3, 1)
box.box()
for row in range(1,rows+1):
    box.addstr(row,1,string[(row*columns)-columns:(row*columns)])
    box.refresh()

x = screen.getch()
while x != 27:
    x = screen.getch()
curses.endwin()
exit()

可能重复的可能重复的可能重复的可能重复的