![](/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.