Take Screenshot in Python

Hardeep Kaur
1 min readJul 15, 2020

This is a very basic yet cool functionality you can implement in python.

Open your Python IDE (PyCharm or any other editor) and start writing the below code

import pyautogui  def screenshot():

myScreenshot = pyautogui.screenshot()
myScreenshot.show()
myScreenshot.save('C:\Users\Asus\Desktop\Test\screenshot1.png')
screenshot()

Firstly, download the pyautogui package and import them in your program. you can use following command to install pyautogui package

pip install pyautogui

Then, we’ll define our function named ‘screenshot’ where our main code exists.

GUI version for this code using Tkinter

import pyautogui
import tkinter as tk

root= tk.Tk()

canvas1 = tk.Canvas(root, width = 300, height = 300)
canvas1.pack()

def takeScreenshot ():

myScreenshot = pyautogui.screenshot()
myScreenshot.save(r'C:\Users\Ron\Desktop\Test\screenshot2.png')

myButton = tk.Button(text='Take Screenshot', command=takeScreenshot, bg='green',fg='white',font= 10)
canvas1.create_window(150, 150, window=myButton)

root.mainloop()

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Hardeep Kaur
Hardeep Kaur

Written by Hardeep Kaur

Software Engineer at Google, Ex- Smallcase

No responses yet

Write a response