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,

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")

    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")

        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")

        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")

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

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

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

        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_entry.get()
        if not os.path.exists(

    def start_capture(self):
        self.status_label.config(text="Running", foreground='#8fce00')

        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_entry.get()

        self.is_capturing = True

    def stop_capture(self):
        self.status_label.config(text="Stopped", foreground='#f44336')
        self.is_capturing = False

    def capture_images(self):
        while self.is_capturing:
                im = ImageGrab.grab(bbox=self.monitor)
      , f'{self.mob}_{self.img}.jpg'))
                self.img += 1
            except Exception as e:
                messagebox.showerror("Error", str(e))
                self.is_capturing = False

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

Step 3: Run the Application

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


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


  • 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.


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.

Leave a Reply

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