简体   繁体   English

调整curses 终端的大小不会调整程序窗口的大小

[英]Resizing the curses terminal doesn't resize the program window

I'm on Windows, where the curses module is not native, so I am using the Windows curses module for python 3.2, found here .我在 Windows 上,curses 模块不是本地的,所以我使用 Windows 的curses 模块用于python 3.2,找到here

My goal is to resize the terminal, which is currently at a small 25 lines x 80 columns size.我的目标是调整终端的大小,目前终端的大小为 25 行 x 80 列。 First I tried the curses.resizeterm(lines, cols) command, which is apparently not found in the windows curses module (and hasattr(curses, 'resizeterm') returned false).首先,我尝试了curses.resizeterm(lines, cols)命令,该命令显然在windows 的curses 模块中找不到(并且hasattr(curses, 'resizeterm')返回false)。 So I look at the alternative module unicurses, which is also for windows, but that doesn't even have a resize command.所以我查看了替代模块 unicurses,它也适用于 Windows,但它甚至没有调整大小命令。

So I do more reading and learn about the environment variables 'LINES' and 'COLS' which, when set by os.environ , should resize the terminal.所以我做了更多的阅读和了解环境变量'LINES''COLS' ,当由os.environ设置时,应该调整终端的大小。 And they do, kind of.他们确实,有点。 The terminal itself gets resized, but the Windows program displaying the terminal is still the same size as before, 25 x 80. I have confirmed that the two variables have indeed been changed, writing a little thing to display them in the top left corner.终端本身被调整了大小,但显示终端的 Windows 程序仍然和以前一样大小,25 x 80。我已经确认这两个变量确实已经改变了,写了一点东西在左上角显示它们。 In addition, the box() function does draw a border around the screen as if it the variables were changed.此外, box()函数确实在屏幕周围绘制了一个边框,就好像变量被更改了一样。

So, can anyone explain either 1) how to resize the "Windows window" to match the terminal or 2) how to get resizeterm() to work on my python installation?那么,任何人都可以解释 1) 如何调整“Windows 窗口”的大小以匹配终端或 2) 如何让resizeterm()在我的 python 安装上工作? The relevant code of my program and a picture of how it looks are attached below.我的程序的相关代码和它的外观图片附在下面。

控制台截图

import random, sys, math, curses, os
from curses import *

curses.use_env(True)
os.environ['LINES'] = "80"
os.environ['COLS'] = "60"

stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
curses.start_color()
stdscr.keypad(1)
curses.curs_set(0)

LINES, COLS = stdscr.getmaxyx()

This code might help:此代码可能有帮助:

 import curses

 screen = curses.initscr()

 # Check if screen was re-sized (True or False)
 resize = curses.is_term_resized(y, x)

 # Action in loop if resize is True:
 if resize is True:
     y, x = screen.getmaxyx()
     screen.clear()
     curses.resizeterm(y, x)
     screen.refresh()

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

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