Save screenshot of [Python] [Windows] screen as an image

at first

I needed to save a screenshot of the extended screen, so I wrote it simply.

policy

    1. Speaking of screenshots, press the PrtSc key (PyAutoGUI)
  1. Save clipboard contents (PIL)

prtsc.py


import pyautogui
from PIL import ImageGrab

#Specify the location and file name you want to save
fo = r"C:\Users\hoge\Pictures\Screenshots\desktop.png "

pyautogui.press('printscreen')

im = ImageGrab.grabclipboard()
im.save(fo)

Supplement

Please google to install PyAutoGUI and PIL of your module. I don't remember ...

Recommended Posts

Save screenshot of [Python] [Windows] screen as an image
Create an environment of 64bit Windows + python 2.7 + MeCab 0.996
Crop Numpy.ndarray and save it as an image
The story of making a tool to load an image with Python ⇒ save it as another name
Save the input video from the capture board as an image
Understand the function of convolution using image processing as an example
Cut out an image with python
Image capture of firefox using python
Grayscale image and save as csv
Save the result of the life game as a gif with python
Format when passing a long string as an argument of python
Calculate the editing distance as an index of pronunciation similarity [python]
Extract feature points of an image
Ideone> Python version: 3.5 (as of August 29, 2017)
Send image with python, save with php
[Python] Reason for dtype "int32" in Numpy (Windows environment) (as of September 2020)
Python: Basics of image recognition using CNN
The story of making Python an exe
Python: Application of image recognition using CNN
Shared screen screenshot exe app with python
[Python] [Windows] Take a screen capture in Python
[Python] Calculation of image similarity (Dice coefficient)
Grayscale by matrix-Reinventor of Python image processing-
Drawing with Matrix-Reinventor of Python Image Processing-
Analysis of X-ray microtomography image by Python
Matrix Convolution Filtering-Reinventor of Python Image Processing-
Python> function> Example of taking function as an argument> map (lambda x: 2 ** x, [1, 2, 3]) / locals () ['myprint'] (3.1415, 2.718)
Automatically save images of your favorite characters from Google Image Search with Python
Example of taking Python> function> * args as arguments
Machine learning of sports-Analysis of J-League as an example-②
Color page judgment of scanned image with python
How to crop an image with Python + OpenCV
Image processing? The story of starting Python for
Image Processing with Python Environment Setup for Windows
Create an image with characters in python (Japanese)
[Python] Automatically generate an example animation list-like image.
Post an article with an image to WordPress with Python
[Python + OpenCV] Whiten the transparent part of the image
Note: The meaning of specifying only * (asterisk) as an argument in the Python function definition.
Don't take an instance of a Python exception class directly as an argument to the exception class!
[Python] Save the result of web scraping the Mercari product page on Google Colab to Google Sheets and display the product image as well.