Skip to content

Commit 216b174

Browse files
authored
Add files via upload
1 parent ffec347 commit 216b174

File tree

5 files changed

+186
-2
lines changed

5 files changed

+186
-2
lines changed

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,30 @@
1-
# Snipping-Tool-with-Python
2-
A snipping tool developed using python that can allow you to snip/screenshot the image and it will save it in the folder automatically.
1+
# Snipping Tool with Python
2+
### Installation
3+
1) **Install Python** from https://www.python.org/downloads/
4+
2) **Install Dependencies**
5+
Open cmd in the folder Snipping Tool and run this command
6+
```ruby
7+
pip install -r requirements.txt
8+
```
9+
3) After installing the dependencies, run the py file **OR** write this command in cmd and enter
10+
```ruby
11+
python snipping.py
12+
```
13+
### Information
14+
This Tool is developed using **Python**. Following are the libraries used:
15+
1) **Tkinter**
16+
2) **Pyautogui**
17+
18+
This tool allows the user to take a screenshot in the snipping style and it will display the coordinates information along with the mouse position.
19+
20+
**The snipped imaged will be saved in the same folder with name Capture.png**
21+
22+
### Extras
23+
An exe file is also included in the folder which can run in any pc without python. **Just Like a Snipping Tool Application!!**
24+
*Double Click on the snipping.exe file to run*
25+
26+
The Tool is developed by [Muhammad Osama](https://github.com/Osama710)
27+
28+
## Screenshots
29+
![](screenshots/main.png)
30+
![](screenshots/info.png)

Screenshots/info.PNG

19.4 KB
Loading

Screenshots/main.PNG

11.6 KB
Loading

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tk
2+
pyautogui

snipping.py

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import tkinter as tk
2+
from tkinter import *
3+
import pyautogui
4+
import webbrowser
5+
from tkinter import ttk, messagebox
6+
7+
class Application():
8+
def __init__(self) -> None:
9+
10+
self.bg = "#00203F"
11+
self.fg = "#ADEFD1"
12+
13+
self.main_window = self.createWindow("Snipping Tool")
14+
self.main_window.config(bg=self.bg)
15+
16+
self.title = tk.Label(self.main_window, text="SNIPPING TOOL", font=("HELVETICA",28,"bold"),bg=self.bg,fg=self.fg)
17+
self.title.grid(row=0,column=0,sticky=N,pady=(40,20),padx=40)
18+
19+
self.desc = tk.Label(self.main_window, text="Click the button below and snip the image.",font=("ARIAL",12),bg=self.bg,fg=self.fg)
20+
self.desc.grid(row=1,column=0,padx=20, pady=20)
21+
22+
self.snip_button = tk.Button(self.main_window,text="Snip image", font=("TIMES NEW ROMAN",14),bg=self.fg,fg=self.bg, height = 2, width = 12, command = self.snipImage, bd=7, relief=RAISED)
23+
self.snip_button.grid(row=2,column=0, pady=30,padx=20)
24+
25+
self.menu = tk.Menu(self.main_window)
26+
27+
self.info = tk.Menu(self.menu,tearoff=0)
28+
self.info.add_command(label="Muhammad Osama", command=self.opengit)
29+
30+
self.menu.add_cascade(label="Developed By",menu=self.info)
31+
32+
self.ex = tk.Menu(self.menu,tearoff=0)
33+
self.ex.add_command(label="Exit",command=self.eex)
34+
35+
self.menu.add_cascade(label="Exit",menu=self.ex)
36+
37+
self.main_window.config(menu=self.menu)
38+
39+
#bring to front
40+
self.raise_above_all(self.main_window)
41+
42+
def startMainLoop(self):
43+
""" Driver method """
44+
self.main_window.mainloop()
45+
46+
#widget creation method
47+
def createWindow(self,title):
48+
window = tk.Tk()
49+
window.title(title)
50+
window.geometry("")
51+
return window
52+
53+
def takeBoundedScreenShot(self, x1, y1, x2, y2):
54+
im = pyautogui.screenshot(region=(x1, y1, x2, y2))
55+
im.save("Capture.png")
56+
57+
def snipImage(self):
58+
self.rect = None
59+
self.x = self.y = 0
60+
self.start_x = None
61+
self.start_y = None
62+
self.curX = None
63+
self.curY = None
64+
65+
self.master_screen = Toplevel(self.main_window)
66+
self.master_screen.withdraw()
67+
self.master_screen.attributes("-transparent", "blue")
68+
self.picture_frame = Frame(self.master_screen, background = "blue")
69+
self.picture_frame.pack(fill=BOTH, expand=YES)
70+
71+
self.master_screen.deiconify()
72+
self.main_window.withdraw()
73+
74+
self.screenCanvas = Canvas(self.picture_frame, cursor="cross", bg="grey11")
75+
self.screenCanvas.pack(fill=BOTH, expand=YES)
76+
77+
self.screenCanvas.bind("<ButtonPress-1>", self.on_button_press)
78+
self.screenCanvas.bind("<B1-Motion>", self.on_move_press)
79+
self.screenCanvas.bind("<ButtonRelease-1>", self.on_button_release)
80+
81+
self.master_screen.attributes('-fullscreen', True)
82+
self.master_screen.attributes('-alpha', .3)
83+
self.master_screen.lift()
84+
self.master_screen.attributes("-topmost", True)
85+
86+
def on_button_release(self, event):
87+
separator = ttk.Separator(self.main_window, orient='horizontal')
88+
separator.place(y=40,relx=0, rely=0.47, relwidth=1)
89+
90+
self.inf = tk.Label(self.main_window,text="Screenshot Information", font=("HELVETICA",14,"bold"),bg=self.bg,fg=self.fg)
91+
self.inf.grid(row=3,column=0,padx=20,pady=20)
92+
93+
self.lbl = tk.Label(self.main_window, text=str(self.start_x)+"\n"+str(self.start_y)+"\n"+str(self.curX)+"\n"+str(self.curY), font=("HELVETICA",12),bg=self.bg,fg=self.fg)
94+
self.lbl.grid(row=4,column=0,padx=20)
95+
96+
separator = ttk.Separator(self.main_window, orient='horizontal')
97+
separator.place(y=240,relx=0, rely=0.47, relwidth=1)
98+
99+
self.inff = tk.Label(self.main_window,text="Mouse Position", font=("HELVETICA",14,"bold"),bg=self.bg,fg=self.fg)
100+
self.inff.grid(row=5,column=0,padx=20,pady=20)
101+
102+
self.pos = tk.Label(self.main_window,text="", font=("HELVETICA",12),bg=self.bg,fg=self.fg)
103+
104+
if self.start_x <= self.curX and self.start_y <= self.curY:
105+
self.pos["text"] = "From Left to Downward"
106+
self.takeBoundedScreenShot(self.start_x, self.start_y, self.curX - self.start_x, self.curY - self.start_y)
107+
108+
elif self.start_x >= self.curX and self.start_y <= self.curY:
109+
self.pos["text"] = "From Right to Downward"
110+
self.takeBoundedScreenShot(self.curX, self.start_y, self.start_x - self.curX, self.curY - self.start_y)
111+
112+
elif self.start_x <= self.curX and self.start_y >= self.curY:
113+
self.pos["text"] = "From Left to Upward"
114+
self.takeBoundedScreenShot(self.start_x, self.curY, self.curX - self.start_x, self.start_y - self.curY)
115+
116+
elif self.start_x >= self.curX and self.start_y >= self.curY:
117+
self.pos["text"] = "From Right to Upward"
118+
self.takeBoundedScreenShot(self.curX, self.curY, self.start_x - self.curX, self.start_y - self.curY)
119+
120+
self.pos.grid(row=6,column=0,padx=20,pady=10)
121+
122+
self.master_screen.withdraw()
123+
124+
messagebox.showinfo("Done!","Screenshot Taken and Saved!")
125+
126+
self.main_window.deiconify()
127+
return event
128+
129+
def on_button_press(self, event):
130+
# save mouse drag start position
131+
self.start_x = self.screenCanvas.canvasx(event.x)
132+
self.start_y = self.screenCanvas.canvasy(event.y)
133+
134+
self.rect = self.screenCanvas.create_rectangle(self.x, self.y, 1, 1, outline='red', width=3, fill="blue")
135+
136+
def on_move_press(self, event):
137+
self.curX, self.curY = (event.x, event.y)
138+
# expand rectangle as you drag the mouse
139+
self.screenCanvas.coords(self.rect, self.start_x, self.start_y, self.curX, self.curY)
140+
141+
def raise_above_all(self, window):
142+
""" brings window to the front """
143+
window.attributes('-topmost', 1)
144+
window.attributes('-topmost', 0)
145+
146+
def opengit(self):
147+
webbrowser.open("https://www.flowcode.com/page/osamayousuf")
148+
149+
def eex(self):
150+
self.main_window.destroy()
151+
sys.exit()
152+
153+
app = Application()
154+
app.startMainLoop()

0 commit comments

Comments
 (0)