Reprint explains 4 ways to take screenshots in Python
This article was last updated on: July 24, 2024 am
Python screenshot method
Today, I will share with you a detailed explanation of the 4 ways to get screenshots in Python, which has good reference value, and I hope it will be helpful to you.
Python can get screenshots of computers in several ways, as follows:
PIL
ImageGrab
module- windows API
PyQt
pyautogui
PIL
ImageGrab
module
1 |
|
Use PIL ImageGrab
The module is simple, but the efficiency is a bit low, and it takes 0.5s to take a screenshot.
windows API
Calling Windows APIs is fast but more complicated to use, so I won’t go into detail here, because there are better PyQt to use.
PyQt
PyQt is much simpler than calling the windows API and has many advantages of the Windows API, such as speed, and the ability to specify the window to get, even if the window is occluded. It should be noted that screenshots cannot be obtained when the window is minimized.
You first need to get a handle to the window.
1 |
|
The program prints the window’s hwnd
and title
pregnant title
You can take a screenshot.
1 |
|
pyautogui
pyautogui
It is relatively simple, but you can’t specify the window to get the program, so the window can’t be occluded, but you can specify the location of the screenshot, 0.04s a screenshot, slightly slower than PyQt, but also fast.
1 |
|
Original link
📑Original:
4 Ways to Get Screenshots in Python_Python_Script House (jb51.net)
Modify Date: 2019-08-27 15:33:08 Author: Sunji\