![](/img/trans.png)
[英]How to set the root window size to half of the screen width and height Python Tkinter
[英]Use Python to resize the active window to half the screen size in Linux?
这个问题是后续问题: 通过编译代码在linux中操纵窗口大小?
对于标题,我想将活动窗口的大小调整为屏幕大小的一半(在屏幕的左侧或右侧。我可以使用bash脚本来做到这一点,如下所示(根据上一个问题的答案):
#!/bin/bash
w_h=$(xrandr | awk '/\*/{sub(/[0-9\.\*\+]*$/, ""); sub("x", " "); $1=$1/2; print}')
w=${w_h% *} ; h=${w_h#* }
wmctrl -r :ACTIVE: -b remove,maximized_horz,maximized,vert
wmctrl -r :ACTIVE: -e 0,${w},0,${w},${h}
但是,此方法在我的笔记本电脑上有0.25秒的明显但不严重的滞后,我希望降至0.1秒。 如何获得与上述bash脚本在python中相同的效果?
您得到的延迟是由xrandr命令引起的,无论如何它都会变慢。 您可以通过解析xdpyinfo | grep 'dimensions:'
输出来减少此时间xdpyinfo | grep 'dimensions:'
xdpyinfo | grep 'dimensions:'
。 在python中,您可以使用subprocess.Popen调用此命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.