简体   繁体   English

在python curses中获取更新的屏幕大小

[英]get updated screen size in python curses

I'm using the curses library in python and the only way I know to get the dimensions of the screen is with curses.LINES and curses.COLS . 我在python中使用curses库,并且我知道获取屏幕尺寸的唯一方法是使用curses.LINEScurses.COLS However, those values never get updated, even when a "KEY_RESIZE" key is read, like in the following example: 但是,即使读取了"KEY_RESIZE"键,这些值也永远不会更新,如以下示例所示:

import curses

f = open("out.log", "w")

def log(msg):
    f.write(msg)
    f.flush()

stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(True)

while True:
    stdscr.clear()
    stdscr.refresh()
    key = stdscr.getkey()
    log(key)
    if key == "KEY_RESIZE":
        log("{} {}".format(curses.LINES, curses.COLS))
    if key == "q":
        break

stdscr.keypad(False)
curses.nocbreak()
curses.echo()
curses.endwin()

f.close()

In my output file out.log , I can see that when I resize the curses window, it correctly writes KEY_RESIZE y, but the value of curses.LINES and curses.COLS doesn't get updated. 在我的输出文件out.log ,可以看到当我调整curses窗口的大小时,它正确地写入了KEY_RESIZE y,但是curses.LINEScurses.COLS的值没有得到更新。 What I am missing? 我缺少什么?

使用rows, cols = stdscr.getmaxyx()代替curses.LINEScurses.COLS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM