I'm currently looking to find a module, or code that would allow me to capture another processes window.
I've tried working with ImageGrab, however that just captures an area of the screen rather than binding to a specific process window. Since I'm working with a small monitor I can't guarantee that something won't lap over onto the captured area of the screen, so sadly the ImageGrab solution isn't good enough.
You can achieve this using win32gui.
from PIL import ImageGrab
import win32gui
hwnd = win32gui.FindWindow(None, r'Window_Title')
win32gui.SetForegroundWindow(hwnd)
dimensions = win32gui.GetWindowRect(hwnd)
image = ImageGrab.grab(dimensions)
image.show()
You could also move the window to a preferred position if a small screen is the problem.
win32gui.MoveWindow(hwnd, 0, 0, 500, 700, True)
see win32gui.MoveWindow
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With