Take Screenshot in Python
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()