How to screenshot on windows

Take Screenshots with python Tkinter

In this tutorial, we’ll guide you through the process of how to screenshot on windows by creating a Python application using the Tkinter library. It allows you to capture screenshots at regular intervals simply by clicking a button. This simple Tkinter application provides a user-friendly interface for configuring various settings and controlling the screenshot capture process. Follow the steps below to set up and use the provided code for the take_screenshot_loop application.

Step 1: Install Required Libraries

Before you start, ensure you have Python installed on your system. Additionally, install the required libraries using the following command in your terminal or command prompt:

pip install pillow tkinter

Step 2: How to screenshot on windows: Saving the Code

Copy the provided code and save it in a file, for example, screenshot_looper.py.

import time
import os
from PIL import ImageGrab
import tkinter as tk
from tkinter import ttk, messagebox

class TakeScreenshots:
    def __init__(self, master):
        self.master = master
        self.master.title("Take Screenshot Looper")
        self.master.geometry('300x450')
        self.create_widgets()

    def create_widgets(self):
        ttk.Label(self.master, text="Object File Name:").pack(pady=5)
        self.mob_entry = ttk.Entry(self.master)
        self.mob_entry.insert(0, "example")
        self.mob_entry.pack(pady=5)

        ttk.Label(self.master, text="Monitor (left, top, right, bottom):").pack(pady=5)
        self.monitor_entry = ttk.Entry(self.master)
        self.monitor_entry.insert(0, "40, 0, 800, 640")
        self.monitor_entry.pack(pady=5)

        ttk.Label(self.master, text="Display Time (seconds):").pack(pady=5)
        self.display_time_entry = ttk.Entry(self.master)
        self.display_time_entry.insert(0, "0.5")
        self.display_time_entry.pack(pady=5)

        ttk.Label(self.master, text="Initial Image Index:").pack(pady=5)
        self.img_entry = ttk.Entry(self.master)
        self.img_entry.insert(0, "0")
        self.img_entry.pack(pady=5)

        ttk.Label(self.master, text="Directory:").pack(pady=5)
        self.directory_entry = ttk.Entry(self.master)
        self.directory_entry.insert(0, "./datasets/osrs/")
        self.directory_entry.pack(pady=5)

        self.status_label = ttk.Label(self.master, text="")
        self.status_label.pack(pady=10)

        ttk.Button(self.master, text="Start", command=self.start_capture).pack(pady=5)
        ttk.Button(self.master, text="Stop", command=self.stop_capture, state=tk.DISABLED).pack(pady=5)

        self.img = 0
        self.is_capturing = False

    def ensure_dir(self):
        self.directory = self.directory_entry.get()
        if not os.path.exists(self.directory):
            os.makedirs(self.directory)

    def start_capture(self):
        self.status_label.config(text="Running", foreground='#8fce00')
        self.master.iconify()
        time.sleep(0.2)

        self.mob = self.mob_entry.get()
        monitor_values = list(map(int, self.monitor_entry.get().split(',')))
        self.monitor = tuple(monitor_values)
        self.display_time = float(self.display_time_entry.get())
        self.img = int(self.img_entry.get())
        self.directory = self.directory_entry.get()

        self.is_capturing = True
        self.start_button.config(state=tk.DISABLED)
        self.stop_button.config(state=tk.NORMAL)
        self.capture_images()

    def stop_capture(self):
        self.status_label.config(text="Stopped", foreground='#f44336')
        self.is_capturing = False
        self.start_button.config(state=tk.NORMAL)
        self.stop_button.config(state=tk.DISABLED)

    def capture_images(self):
        while self.is_capturing:
            try:
                im = ImageGrab.grab(bbox=self.monitor)
                im.save(os.path.join(self.directory, f'{self.mob}_{self.img}.jpg'))
                self.img += 1
                time.sleep(self.display_time)
                self.master.update()
            except Exception as e:
                messagebox.showerror("Error", str(e))
                self.is_capturing = False

if __name__ == "__main__":
    root = tk.Tk()
    app = TakeScreenshots(root)
    root.mainloop()

Step 3: Run the Application

Open a terminal or command prompt, navigate to the directory containing the saved script (screenshot_looper.py), and run the following command:

python screenshot_looper.py

Step 4: Configure Settings

Once the application window opens, you’ll see several Entry widgets to input the following settings:

  • Object File Name: The prefix for the screenshot filenames.
  • Monitor (left, top, right, bottom): Define the area on the screen to capture in the format left, top, right, bottom.
  • Display Time (seconds): Set the time interval between each screenshot.
  • Initial Image Index: The starting index for the screenshot filenames.
  • Directory: The directory where screenshots will be saved.

Step 5: Start and Stop Capture

Click the “Start” button, this is how to screenshot on windows which is to initiate the screenshot capture process with the specified settings. To stop capturing screenshots, click the “Stop” button.

How to take a screenshot in windows - the gui made with python

Step 6: Review Captured Screenshots

Navigate to the specified directory to find the captured screenshots. The filenames will be in the format {object_file_name}_{image_index}.jpg.

How to take a screenshot in windows - the output folder

Notes

  • If the specified directory does not exist, the application will create it.
  • If an error occurs during the capture process, an error message will be displayed.

Conclusion

This Tkinter application provides a convenient way on how to screenshot on windows by capturing screenshots at regular intervals, making it useful for various tasks such as creating datasets or monitoring visual changes over time. Customize the settings based on your specific requirements, and enjoy the ease of capturing screenshots with this user-friendly interface. Whether you’re a developer, data scientist, or simply someone who needs periodic screenshots, this application streamlines the process for you.

Want to know how the code works? TBA soon for tutorial on how the elements and functions work in this screenshot tkinker application.

82 thoughts on “How to screenshot on windows

  1. Wow, amazing weblog format! How lengthy have you been blogging for? you make running a blog glance easy. The whole look of your web site is magnificent, as neatly as the content material!

  2. Thank you for sharing excellent informations. Your web-site is so cool. I am impressed by the details that you’ve on this blog. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for extra articles. You, my pal, ROCK! I found just the info I already searched all over the place and simply could not come across. What a perfect web-site.

  3. Thank you so much for giving everyone an exceptionally superb possiblity to read critical reviews from here. It can be very cool and as well , packed with amusement for me and my office colleagues to search your web site minimum thrice every week to find out the newest issues you have. Of course, I’m so at all times amazed considering the impressive techniques you serve. Selected 4 areas in this posting are unquestionably the simplest we have all ever had.

  4. Yesterday, while I was at work, my cousin stole my iPad and tested to see if it can survive a forty foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views. I know this is completely off topic but I had to share it with someone!

  5. Good site! I really love how it is simple on my eyes and the data are well written. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your feed which must do the trick! Have a great day!

  6. I cling on to listening to the reports talk about receiving boundless online grant applications so I have been looking around for the finest site to get one. Could you tell me please, where could i acquire some?

  7. Somebody essentially help to make seriously articles I would state. This is the very first time I frequented your website page and thus far? I amazed with the research you made to create this particular publish amazing. Magnificent job!

  8. Excellent goods from you, man. I’ve be aware your stuff previous to and you’re just too great. I really like what you’ve bought right here, certainly like what you’re stating and the way in which in which you assert it. You make it enjoyable and you continue to care for to keep it smart. I can’t wait to read much more from you. This is really a terrific site.

  9. An fascinating dialogue is value comment. I feel that you need to write extra on this topic, it won’t be a taboo topic but typically people are not sufficient to speak on such topics. To the next. Cheers

  10. Hi, I do think this is a great blog. I stumbledupon it 😉 I will revisit yet again since I saved as a favorite it. Money and freedom is the best way to change, may you be rich and continue to help others.

  11. I don’t even know how I ended up here, but I believed this post used to be good. I don’t recognise who you might be however certainly you’re going to a famous blogger should you are not already 😉 Cheers!

  12. พนันบอลอย่างไรให้ได้เงิน แทงบอลชนะอย่างไรไม่ถูกโกง UFABET จ่ายจริงจ่ายไม่ยั้งระบบเข้าใจง่าย แค่เพียงคลิกสมัครก็ทำเงินได้อย่างง่ายๆกับคาสิโนออนไลน์ สบายสุดๆชีวิตชิวๆชีวิตคลูๆทำเงิน สร้างกำไรสบายๆจึงควรที่ UFABET

  13. Hey just wanted to give you a quick heads up and let you know afew of the images aren’t loading correctly.I’m not sure why but I think its a linking issue.I’ve tried it in two different browsers and both show the sameresults.

  14. An intriguing discussion is definitely worth comment. I think that you need to publish more about this topic, it might not be a taboo subject but generally people don’t speak about these issues. To the next! Best wishes!!

  15. Hi i am kavin, its my first time to commenting anywhere,when i read this post i thought i could also make comment due to this brilliantparagraph.

  16. This is a really good tip particularly to those fresh to the blogosphere.Simple but very precise info… Appreciate your sharing this one.A must read post!my blog – eczema remedies

  17. Heya! I just wanted to ask if you ever have any trouble with hackers?My last blog (wordpress) was hacked and I ended up losing several weeks of hard work due to no backup.Do you have any methods to protect against hackers?

  18. Does anyone know if I am able to purchase JUSTKRATOM Red Maeng Da Kratom Capsules (justkratomstore.com) from American Pure Vapor, 1830 NE Pine Island Road #110, Cape Coral, FL, 33909?

  19. These are truly wonderful ideas in on the topic of blogging.You have touched some nice points here. Any way keep up wrinting.

  20. Hey! This post could not be written any better! Reading through this post reminds me of my good old room mate! He always kept talking about this. I will forward this post to him. Pretty sure he will have a good read. Thanks for sharing!

  21. Hi, I do believe this is an excellent blog. I stumbledupon it 😉 I am going to revisit once again since I bookmarked it. Money and freedom is the greatest way to change, may you be rich and continue to help other people.

  22. What’s up, I wish for to subscribe for this blog to take newest updates, thus where can i do it pleasehelp out.Here is my blog post :: Niagara XL Review

  23. Nice post. I used to be checking constantly this blog and I am inspired!Extremely helpful info specially the closing part 🙂 I handle suchinfo much. I was looking for this certain info for a long time.Thank you and good luck.

Leave a Reply

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