Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取curses main循环中的终端窗口大小_Python_Terminal_Resize_Window_Curses - Fatal编程技术网

Python 获取curses main循环中的终端窗口大小

Python 获取curses main循环中的终端窗口大小,python,terminal,resize,window,curses,Python,Terminal,Resize,Window,Curses,我有一个脚本,我想打印当前终端窗口大小每次改变 以下是我的代码示例: import curses def main(): stdscr = curses.initscr() seq = 0 while 1: stdscr.refresh() ch = stdscr.getch() seq += 1 if ch == curses.KEY_RESIZE: stdscr.addstr(1

我有一个脚本,我想打印当前终端窗口大小每次改变

以下是我的代码示例:

import curses

def main():
    stdscr = curses.initscr()
    seq = 0
    while 1:
        stdscr.refresh()
        ch = stdscr.getch()
        seq += 1
        if ch == curses.KEY_RESIZE:
            stdscr.addstr(1, 0, ','.join(str(_) for _ in stdscr.getmaxyx())+' '+str(seq))                                                  
            stdscr.refresh()

    curses.endwin()
    return 0

if __name__ == '__main__':
    main()
它的问题是,尽管getch()成功地调整了键的大小,但stdscr.getmaxyx()始终返回相同的值。 谢谢

更新
事实证明,问题出在LinuxMintNcurses库上,在debian和我检查过的所有基于rpm的发行版上,一切都很好。这可能适用于ubuntu及其其他衍生产品。

您使用的是什么操作系统/终端?使用PuTTY连接到Linux(Fedora)box,代码可以正常工作。使用terminator/gnome terminal/xterm的ubuntu不想工作。我可能应该和其他人一起尝试。奇怪的是,我只是用其他ubuntu盒子尝试了一下,而且效果很好。有趣的是,我错了,在Debian Wheezy上工作,在Linux上不工作,在gnome终端的Ubuntu14.04上使用Python3