实例如下:
引入库:
from PyQt5.QtWidgets import QApplication
import win32gui
import sys
实现截屏:
h2b = win32gui.FindWindow(None, 'C:\Windows\system32\c md.exe')
app = QApplication(sys.argv)
screen = QApplication.primaryScreen()
保存图片:
img = screen.grabWindow(h2b).toImage()
img.save("screenshot1.jpg")
完整代码:
from PyQt5.QtWidgets import QApplication
import win32gui
import sys
h2b = win32gui.FindWindow(None, 'C:\Windows\system32\cmd.exe')
app = QApplication(sys.argv)
screen = QApplication.primaryScreen()
img = screen.grabWindow(h2b).toImage()
print('截屏成功')
img.save("screenshot1.jpg")