python运行界面如何缩小,想要在python中调整终端窗口的大小,可以运行,但不太正确...

I'm attempted to resize the terminal window on launch of a python script to ensure the display will be static size. It's working but not quite what I expected. I've tried a few methods:

import sys

sys.stdout.write("\x1b[8;40;120t")

and

import subprocess

subprocess.call(["echo","-e","\x1b[8;40;120t"])

and even just

print "\x1b[8;40;80t"

They all work and resize the real terminal. However, if my terminal is, let's say 25x80 to start, the script starts, it resizes, then exits. It will not execute the rest of the script. I wrapped it in a try/Except and nothing is thrown. Nothing in the syslogs and python -v script.py shows nothing odd. If I execute the script again or at a term size of 40x120 (my target size)..the script runs just fine. Why is exeecuting the ANSI escape exiting python? Furthermore if I run this interactively it works with no issues.

Using Python 2.6.6.

解决方案

I tried to run the following script, and it "works" (Linux Debian / Python 2.6 / gnome-terminal):

print "\x1b[8;40;80t"

print "ok"

The window is resized and the script execution continue.

If you confirm in your case the program stops after resizing, my guess would be Python received a signal SIGWINCH when the window is resized.

You should try to add a specific signal handler. Something like that:

def resizeHandler(signum, frame):

print "resize-window signal caught"

signal.signal(signal.SIGWINCH, resizeHandler)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值