获取窗口位置 &大小与蟒蛇 [英] Get window position & size with python

查看:32
本文介绍了获取窗口位置 &大小与蟒蛇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用python获取和设置窗口(任何windows程序)的位置和大小?

How can I get and set the window (any windows program) position and size with python?

推荐答案

假设您使用的是 Windows,请尝试使用 pywin32win32gui 模块及其 EnumWindowsGetWindowRect 函数.

Assuming you're on Windows, try using pywin32's win32gui module with its EnumWindows and GetWindowRect functions.

如果您使用的是 Mac OS X,您可以尝试使用 appscript.

If you're using Mac OS X, you could try using appscript.

对于 Linux,您可以尝试 X11 的众多接口之一.

For Linux, you can try one of the many interfaces to X11.

Windows 示例(未测试):

Example for Windows (not tested):

import win32gui

def callback(hwnd, extra):
    rect = win32gui.GetWindowRect(hwnd)
    x = rect[0]
    y = rect[1]
    w = rect[2] - x
    h = rect[3] - y
    print("Window %s:" % win32gui.GetWindowText(hwnd))
    print("\tLocation: (%d, %d)" % (x, y))
    print("\t    Size: (%d, %d)" % (w, h))

def main():
    win32gui.EnumWindows(callback, None)

if __name__ == '__main__':
    main()

这篇关于获取窗口位置 &大小与蟒蛇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆