Oh Snap!

Please turnoff your ad blocking mode for viewing your site content

Hit enter after type your search item

Python Screenshot Application Using Tkinter and PyAutoGUI Library Full Project For Beginners

/
/
/
61 Views

Welcome folks today in this tutorial we will be building a gui application in python with the help of tkinter and pyautogui library in this application you can take the screenshot of the screen that you are currently viewing on the desktop. The detailed practical video is shown below see the video and understand the concept behind building the application.

 

Screenshots

 

 

 

Now you can see in the screenshot of the app we have the simple gui window that we have made with the help of Tkinter library in Python and then we also need pyautogui to actually take the screenshot and save it to the local system. We also see the file dialog which allows users to save the file into the downloads folder.

READ  Python OpenCV Tutorial To Capture Images From Webcam Full Project

 

Dependencies

 

1) Pip install tkinter

2) Pip install pyautogui

 

Source Code

 

import pyautogui

import tkinter as tk

from tkinter import filedialog

root = tk.Tk()

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

canvas1.pack()

root.mainloop()

 

In this block of code we are importing tkinter library and pyautogui library and we are making a simple window passing the width and height of the window as 300×300 and then we use the pack method to display the window. If you run this script you will see a window.

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

canvas1.create_window(150,150,window=myButton)

 

READ  Python Tutorial Compressing and Extracting Files Using ZipFile Library Full Project

Now we are adding a simple button of Take screenshot with a green background color and a white foreground color We are using a button method of tkinter passing these arguments and then we are placing the button using create_window method passing x and y parameters and also the reference of the button. And we have defined a command which contains the custom function which will be executed when we click the button method : -> takeScreenshot in the next step we will write this function.

READ  Python GUI Tkinter Form Submit Data to Text File Using File Handling

 

def takeScreenshot():
    myScreenshot = pyautogui.screenshot()
    
    file_path = filedialog.asksaveasfilename(defaultextension='.png')
    
    myScreenshot.save(file_path)

 

Now you can see we are taking the screenshot with the pyautogui library and then we are displaying a file dialog to save the file and passing a default extension of .png and then we are setting the file path to the save method of screenshot library pyautogui.

 

Whole Source Code:

 

import pyautogui

import tkinter as tk

from tkinter import filedialog

root = tk.Tk()

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

canvas1.pack()

def takeScreenshot():
    myScreenshot = pyautogui.screenshot()
    
    file_path = filedialog.asksaveasfilename(defaultextension='.png')
    
    myScreenshot.save(file_path)
    


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

canvas1.create_window(150,150,window=myButton)


root.mainloop()

Leave a Comment

Your email address will not be published. Required fields are marked *

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :