以下代码片段应查找“Notes.txt - 记事本”窗口并捕获该窗口的屏幕截图。import pyautoguiimport win32guidef screenshot(window_title="Notes.txt - Notepad"): if window_title: hwnd = win32gui.FindWindow(window_title, None) if hwnd: win32gui.SetForegroundWindow(hwnd) x, y, x1, y1 = win32gui.GetClientRect(hwnd) x, y = win32gui.ClientToScreen(hwnd, (x, y)) x1, y1 = win32gui.ClientToScreen(hwnd, (x1 - x, y1 - y)) im = pyautogui.screenshot(region=(x, y, x1, y1)) return im else: print('Window not found!') else: im = pyautogui.screenshot() return imim = screenshot('Calculator')if im: im.show()这里的问题是,无论我作为 window_title 传递什么,它总是返回:Window not found!当我print(hwnd)评估为0文件标题:
添加回答
举报
0/150
提交
取消