以下代碼片段應查找“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
提交
取消