你可以直接使用win32 API.
原文链接:https://www.f2er.com/windows/371161.html1)首先将焦点放在您要截图的应用程序上.
link text
2)Win32 API可以帮助屏幕截图:
import win32gui import win32ui hwnd = win32gui.FindWindow(None,windowname) wDC = win32gui.GetWindowDC(hwnd) dcObj=win32ui.CreateDCFromHandle(wDC) cDC=dcObj.CreateCompatibleDC() dataBitMap = win32ui.CreateBitmap() dataBitMap.CreateCompatibleBitmap(dcObj,w,h) cDC.SelectObject(dataBitMap) cDC.BitBlt((0,0),(w,h),dcObj,(0,win32con.SRCCOPY) dataBitMap.SaveBitmapFile(cDC,bmpfilenamename) # Free Resources dcObj.DeleteDC() cDC.DeleteDC() win32gui.ReleaseDC(hwnd,wDC) win32gui.DeleteObject(dataBitMap.GetHandle())