Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Desktop Notifier in Python
Next article icon

Python offers multiple libraries to ease our work. Here we will learn how to take a screenshot using Python. Python provides a module calledpyscreenshot for this task. It is only a pure Python wrapper, a thin layer over existing backends. Performance and interactivity are not important for this library.

Installation

Install the package pyscreenshot using the below command in your command prompt.

pip install pyscreenshot

Capturing Full Screen

Here we will learn the simplest way of taking a screenshot using pyscreenshot module. Here we will use the functionshow()to view the screenshot. 

Python3
# Program to take screenshotimportpyscreenshot# To capture the screenimage=pyscreenshot.grab()# To display the captured screenshotimage.show()# To save the screenshotimage.save("GeeksforGeeks.png")

Output:

Full Screenshot

Capturing part of the screen

Here is the simple Python program to capture the part of the screen. Here we need to provide the pixel positions in thegrab() function. We need to pass the coordinates in the form of a tuple. 

Python3
# Program for partial screenshotimportpyscreenshot# im=pyscreenshot.grab(bbox=(x1,x2,y1,y2))image=pyscreenshot.grab(bbox=(10,10,500,500))# To view the screenshotimage.show()# To save the screenshotimage.save("GeeksforGeeks.png")

Output:

Partial Screenshot

Important Points:

  • We need to install pillow (PIL) package before installing pyscreenshot package.
  • Here show() function works as print i.e. It displays the captured screenshot.
  • We need to pass the coordinates in tuple.
  • We can save the screenshot to a file or PIL image memory.

Improve

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp