使用 python 在 windows 中抓取并设置 windows 大小
grabbing and setting windowsize in windows with python
我找遍了,但我还没有找到一种方法来获取 windows 中某个 window 的大小,或者在检查了哪个大小后设置大小是的。
如果有人能帮我找出在哪里搜索,我会很高兴。我也在 windows 10 中使用 python 和 opencv 工作。
我找到了 Selenium WebDriver,但这似乎只适用于浏览器。我想知道除了浏览器之外的其他 windows 是否可行,例如记事本。
总而言之,我想获取某个 window 的大小,如果它不是我想要的正确大小,则更改它。谢谢你和我一起思考。
Module win32gui
Python extensions for Microsoft Windows’ Provides access to much of the Win32 API, the ability to create and use COM objects, and the Pythonwin environment
MoveWindow function: Changes the position and dimensions of the specified window.
syntax: MoveWindow(hwnd, x, y, width, height, bRepaint)
**
import win32gui
#hwnd = win32gui.FindWindow(None, 'Window Title')
hwnd = win32gui.FindWindow(None, 'Untitled - Notepad')
x0, y0, x1, y1 = win32gui.GetWindowRect(hwnd)
w = x1 - x0 # width
h = y1 - y0 # height
win32gui.MoveWindow(hwnd, x0, y0, w-500, h-500, True)
结果:
- 应用程序(全屏拉伸):记事本
- 运行 代码(测试pyCharm,python 3.7 项目解释器)
我找遍了,但我还没有找到一种方法来获取 windows 中某个 window 的大小,或者在检查了哪个大小后设置大小是的。
如果有人能帮我找出在哪里搜索,我会很高兴。我也在 windows 10 中使用 python 和 opencv 工作。
我找到了 Selenium WebDriver,但这似乎只适用于浏览器。我想知道除了浏览器之外的其他 windows 是否可行,例如记事本。
总而言之,我想获取某个 window 的大小,如果它不是我想要的正确大小,则更改它。谢谢你和我一起思考。
Module win32gui
Python extensions for Microsoft Windows’ Provides access to much of the Win32 API, the ability to create and use COM objects, and the Pythonwin environment
MoveWindow function: Changes the position and dimensions of the specified window.
syntax: MoveWindow(hwnd, x, y, width, height, bRepaint) **
import win32gui
#hwnd = win32gui.FindWindow(None, 'Window Title')
hwnd = win32gui.FindWindow(None, 'Untitled - Notepad')
x0, y0, x1, y1 = win32gui.GetWindowRect(hwnd)
w = x1 - x0 # width
h = y1 - y0 # height
win32gui.MoveWindow(hwnd, x0, y0, w-500, h-500, True)
结果:
- 应用程序(全屏拉伸):记事本
- 运行 代码(测试pyCharm,python 3.7 项目解释器)