Skip to content

Commit b4cbcda

Browse files
adithya-r-prabhutechyminati
authored andcommitted
add screenshot_using_python.py
1 parent 113ce47 commit b4cbcda

File tree

1 file changed

+237
-0
lines changed

1 file changed

+237
-0
lines changed
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
import webbrowser, os
2+
3+
import datetime
4+
import pyautogui
5+
import time
6+
7+
from PIL import ImageTk,Image
8+
9+
import glob
10+
import os.path
11+
12+
from tkinter import *
13+
14+
import win32gui
15+
import win32con
16+
17+
18+
tkWindow = Tk()
19+
tkWindow.geometry('195x60')
20+
tkWindow.geometry('+50+980')
21+
22+
23+
24+
tkWindow.title('capyture')
25+
26+
tkWindow.iconbitmap("icons/Untitled design.ico")
27+
28+
# uses win32gui and win32con
29+
def windowEnumHandler(hwnd, top_windows):
30+
top_windows.append((hwnd, win32gui.GetWindowText(hwnd)))
31+
32+
def bringToFront(window_name):
33+
top_windows = []
34+
win32gui.EnumWindows(windowEnumHandler, top_windows)
35+
for i in top_windows:
36+
# print(i[1])
37+
if window_name.lower() in i[1].lower():
38+
# print("found", window_name)
39+
win32gui.ShowWindow(i[0], win32con.SW_SHOWNORMAL)
40+
win32gui.SetForegroundWindow(i[0])
41+
break
42+
43+
n=True
44+
def removetitlebar():
45+
global n
46+
47+
if n:
48+
#with titlebar
49+
tkWindow.overrideredirect(False)
50+
tkWindow.geometry('240x60')
51+
n=False
52+
else:
53+
# without title bar
54+
tkWindow.overrideredirect(True)
55+
tkWindow.geometry('195x60')
56+
n=True
57+
58+
59+
60+
61+
def minimizing():
62+
removetitlebar()
63+
tkWindow.overrideredirect(False)
64+
tkWindow.wm_state('iconic')
65+
tkWindow.iconify()
66+
67+
68+
def screenshot():
69+
#GET THE CURRENT DATE AND TIME
70+
now = datetime.datetime.now()
71+
now_str = time.strftime("%H.%M.%S")
72+
minimizing()
73+
time.sleep(0.5)
74+
outFile = pyautogui.screenshot('ImageFile{}.PNG'.format(now_str))
75+
tkWindow.after(0,tkWindow.focus_force)
76+
if __name__ == "__main__":
77+
winname = "capyture"
78+
bringToFront(winname)
79+
removetitlebar()
80+
81+
82+
83+
84+
85+
86+
def imageviewer():
87+
folder_path = r'C:/Users/user pc/Desktop/screenshotpy'
88+
file_type = '/*PNG'
89+
files = glob.glob(folder_path + file_type)
90+
max_file = max(files, key=os.path.getctime) #path of latest file saved
91+
path=max_file
92+
webbrowser.open(os.path.realpath(path))
93+
94+
95+
preview = Button(tkWindow,
96+
text = 'P ',
97+
font=50,
98+
command = imageviewer,
99+
activebackground="violet",
100+
bg="light blue",
101+
fg='dark blue',
102+
)
103+
104+
105+
106+
107+
108+
109+
110+
111+
112+
113+
capture = Button(tkWindow,
114+
text = 'CAPTUR▷',
115+
font=50,
116+
command = screenshot,
117+
activebackground="violet",
118+
bg="light blue",
119+
fg='dark blue',
120+
)
121+
122+
123+
tkWindow.attributes('-topmost',True)
124+
125+
tkWindow.overrideredirect(True)# for removing title bar
126+
127+
def Close():
128+
tkWindow.destroy()
129+
130+
# Button for closing
131+
exit_button = Button(tkWindow, text="X", command=Close,
132+
font=50,
133+
activebackground="red",
134+
bg="light blue",
135+
fg='dark blue',)
136+
137+
def openfolder():
138+
path="C:/Users/user pc/Desktop/screenshotpy"
139+
webbrowser.open(os.path.realpath(path))
140+
141+
folder_button =Button(tkWindow,text='F',command=openfolder,
142+
font=50,
143+
activebackground="red",
144+
bg="light blue",
145+
fg='dark blue',)
146+
147+
#telegram
148+
def opentelegram():
149+
path="D:/Telegram/Telegram.exe"
150+
webbrowser.open(os.path.realpath(path))
151+
telegram = PhotoImage(file='icons/telegram.png')
152+
telegram_button=Button(tkWindow,
153+
text="TELEGRAM",
154+
image=telegram,compound=LEFT,
155+
command=opentelegram,
156+
activebackground="red",
157+
bg="light green",
158+
fg='dark blue',)
159+
160+
#whattsapp
161+
def openwhattsapp():
162+
path="C:/Users/user pc/AppData/Local/WhatsApp/WhatsApp.exe"
163+
webbrowser.open(os.path.realpath(path))
164+
whattsapp = PhotoImage(file='icons/whattsapp.png')
165+
whattsapp_button=Button(tkWindow,
166+
text="",
167+
image=whattsapp,
168+
command=openwhattsapp,
169+
font=50,
170+
activebackground="red",
171+
bg="light green",
172+
fg='dark blue',)
173+
174+
#edge
175+
def openedge():
176+
path="C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
177+
webbrowser.open(os.path.realpath(path))
178+
edge = PhotoImage(file='icons/edge.png')
179+
edge_button=Button(tkWindow,
180+
text="",
181+
image=edge,
182+
command=openedge,
183+
font=50,
184+
activebackground="red",
185+
bg="light green",
186+
fg='dark blue',)
187+
188+
def openvscode():
189+
path="D:/Microsoft VS Code/Code.exe"
190+
webbrowser.open(os.path.realpath(path))
191+
vscode = PhotoImage(file='icons/vscode.png')
192+
vscode_button=Button(tkWindow,
193+
text="",
194+
image=vscode,
195+
command=openvscode,
196+
font=50,
197+
activebackground="red",
198+
bg="light green",
199+
fg='dark blue',)
200+
201+
202+
203+
204+
#minimizing
205+
minimizing_button=Button(tkWindow,
206+
text="⇲",
207+
font=60,
208+
command=minimizing,
209+
activebackground="red",
210+
bg="light blue",
211+
fg='dark blue',)
212+
213+
214+
215+
216+
217+
218+
removetitlebar_button=Button(tkWindow,
219+
text="▭",
220+
font=60,
221+
command=removetitlebar,
222+
activebackground="red",
223+
bg="light blue",
224+
fg='dark blue',)
225+
226+
capture.grid(row=0, column=0)
227+
preview.grid(row=0, column=1)
228+
folder_button.grid(row=0, column=2)
229+
minimizing_button.grid(row=0,column=3)
230+
exit_button.grid(row=0, column=4)
231+
telegram_button.grid(row=1,column=0)
232+
whattsapp_button.grid(row=1,column=1)
233+
edge_button.grid(row=1,column=2)
234+
vscode_button.grid(row=1,column=3)
235+
removetitlebar_button.grid(row=1,column=4)
236+
237+
tkWindow.mainloop()

0 commit comments

Comments
 (0)