以下代碼片段應(yīng)查找“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()這里的問(wèn)題是,無(wú)論我作為 window_title 傳遞什么,它總是返回:Window not found!當(dāng)我print(hwnd)評(píng)估為0文件標(biāo)題:
無(wú)法捕獲窗口標(biāo)題python
月關(guān)寶盒
2022-06-28 17:30:05