Taking a Screenshot - The Advantages of Learning Python Programming for Beginners: A Comprehensive Guide

Latest

Dive into the world of Python programming with our comprehensive resources

Music

logo

Saturday, February 25, 2023

Taking a Screenshot

 

In this article, a screenshot is taken by clicking the button in the form.



 

 

 

 

 

 

 

Figure 1

 

 


 

 

 

Figure 2

 

 


 

 

 

 

 

 

 

Figure 3

 

 

Add the following library classes into the form.

 

 

from tkinter import *

import time

from PIL import ImageTk, Image

import pyautogui as pg

 

 

root = Tk()

 

root.title("take screenshot..bs")

 

root.geometry("700x350")

 

# Define a function for taking screenshot


 

def screenshot():

   random = int(time.time())

   filename = "D:\\Data\\" + "ScreenImg" +str(random) + ".jpg"

   screenshot = pg.screenshot(filename)

   screenshot.show()

 

# Take a screenshot and then convert it to PDF using python


 

   img = Image.open(filename)

   imc = img.convert('RGB')

   imc.save("D:\\Data\\" + "ScreenImg" +str(random) + ".pdf")

 

   root.deiconify()

 

def hide_rootdow():

 

   # Hiding the tkinter rootdow while taking the screenshot


 

   root.withdraw()

   root.after(1000, screenshot)

 

# Add a Label widget


 

   Label(root, text="Click the Button to Take the Screenshot" + "\n" +" Ekran resimi almak icin butona tiklayiniz", font=('Times New Roman', 18, 'bold')).pack(pady=10)

 

# Create a Button to take the screenshots


 

button = Button(root, text="Take Screenshot", font=('Arial',12,'bold'), bg="fuchsia", fg="white", width=20,height=2, command=hide_rootdow)

button.pack(pady=30)

 

root.mainloop()

 

 

Hope to see you soon. Happy coding

No comments:

Post a Comment

Featured post

Python Introduction

What is Python? Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built ...