我在做一个用Python诅咒的项目。你知道吗
我在while True
循环中使用stdscr.getmaxyx()
来获得当前终端窗口的大小,以便在终端窗口的中心显示文本。你知道吗
下面的代码按预期工作:当运行它并调整终端大小时,文本保持在窗口的中心并显示当前终端大小。你知道吗
import curses
from curses import wrapper
from IPython.core.debugger import Tracer
# debug_here = Tracer()
def main(stdscr):
inp = 'Initial'
while True:
y, x = stdscr.getmaxyx()
curses.curs_set(0)
stdscr.clear()
stdscr.refresh()
stdscr.addstr(int(y/2), int(x/2), '{}x{}'.format(y, x))
stdscr.addstr(int(y/2)+1, int(x/2), inp)
try:
inp = stdscr.getkey()
except curses.error:
inp = '...'
wrapper(main)
当我取消注释第4行(debug_here = Tracer()
)时,代码仍然运行,但是当我调整它的大小时,终端大小没有更新,因此文本并不总是显示在中心。你知道吗
你知道这种行为是否是预期的,以及发生这种情况的原因吗?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐