Skip to content

Commit 0ad6ecc

Browse files
committed
added the screenshot with tkinter gui and also created a new documentation
1 parent 2cffc8f commit 0ad6ecc

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

Screenshot/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Description
2+
The code above creates a simple screenshot tool using the Python tkinter library. The tool allows users to specify a delay in seconds before taking a screenshot. The screenshot is then saved as a PNG file with a timestamped name.
3+
4+
## Setup Instruction
5+
To run the code, you will need to have the Python tkinter and pyautogui libraries installed. You can install them using the following commands:
6+
7+
Here are the steps on how to run the code:
8+
9+
1. Install the Python tkinter and pyautogui libraries.<br/>
10+
``pip install tkinter pyautogui``
11+
12+
2. Save the code as a Python file.<br/>``screenshot.py``
13+
3. Run the code from the command line and write this command:<br/>``python screenshot.py``
14+
4. Specify the delay in seconds before taking a screenshot.
15+
5. Click the "Take Screenshot" button to capture the screenshot.
16+
17+
I hope this helps! Let me know if you have any other questions.
18+
19+
## Requirements
20+
1. python and its libararies like:
21+
- tkinter
22+
- pyautogui
23+
24+
## Screenshots save
25+
- When the screenshot is taken, it is saved as a PNG file with a timestamped name. For example, if the delay is set to 5 seconds and the screenshot is taken at 12:34 PM, the screenshot will be saved as 1234567890.png.

Screenshot/screenshot.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
import time
22
import pyautogui
3+
import tkinter as tk
4+
from tkinter import ttk
35

4-
5-
def screenshot():
6+
def take_screenshot(delay):
67
name = int(round(time.time() * 1000))
78
name = '{}.png'.format(name) # To name the file
8-
time.sleep(5) # Time Wait Before Taking Screenshot
9+
time.sleep(delay) # Time Wait Before Taking Screenshot
910
img = pyautogui.screenshot(name)
1011
img.show() # To Show the Screenshot After Being Taken
1112

13+
def on_take_screenshot():
14+
delay = float(delay_entry.get())
15+
take_screenshot(delay)
16+
17+
# Create the tkinter GUI
18+
root = tk.Tk()
19+
root.title("Screenshot Tool")
20+
root.geometry("300x150")
21+
22+
# Label and Entry for specifying the time delay
23+
delay_label = ttk.Label(root, text="Delay (in seconds):")
24+
delay_label.pack(pady=10)
25+
delay_entry = ttk.Entry(root)
26+
delay_entry.pack(pady=5)
27+
delay_entry.insert(0, "5.0") # Default value
28+
29+
# Button to trigger the screenshot capture
30+
screenshot_button = ttk.Button(root, text="Take Screenshot", command=on_take_screenshot)
31+
screenshot_button.pack(pady=20)
1232

13-
screenshot()
33+
root.mainloop()

0 commit comments

Comments
 (0)