|
| 1 | +# ========================================================== |
| 2 | +# Screenshot PRO - Screen Capture Tool |
| 3 | +# Professional Desktop Tool |
| 4 | +# ========================================================== |
| 5 | + |
| 6 | +import os |
| 7 | +import sys |
| 8 | +import threading |
| 9 | +import time |
| 10 | +import traceback |
| 11 | +from queue import Queue, Empty |
| 12 | + |
| 13 | +import tkinter as tk |
| 14 | +from tkinter import filedialog, messagebox |
| 15 | + |
| 16 | +import ttkbootstrap as tb |
| 17 | +from ttkbootstrap.constants import * |
| 18 | + |
| 19 | +from PIL import ImageGrab |
| 20 | + |
| 21 | + |
| 22 | +# =================== APP CONFIG =================== |
| 23 | + |
| 24 | +APP_NAME = "Screenshot PRO" |
| 25 | +APP_VERSION = "1.0.0" |
| 26 | + |
| 27 | + |
| 28 | +# =================== APP =================== |
| 29 | + |
| 30 | +app = tk.Tk() |
| 31 | +app.title(f"{APP_NAME} {APP_VERSION}") |
| 32 | +app.geometry("1050x620") |
| 33 | + |
| 34 | +tb.Style("darkly") |
| 35 | + |
| 36 | + |
| 37 | +# =================== UTILITY =================== |
| 38 | + |
| 39 | +def resource_path(file_name): |
| 40 | + base_path = getattr(sys, "_MEIPASS", os.path.dirname(os.path.abspath(__file__))) |
| 41 | + return os.path.join(base_path, file_name) |
| 42 | + |
| 43 | + |
| 44 | +def log_error(): |
| 45 | + with open("error.log", "a", encoding="utf-8") as f: |
| 46 | + f.write(traceback.format_exc() + "\n") |
| 47 | + |
| 48 | + |
| 49 | +def show_about(): |
| 50 | + messagebox.showinfo( |
| 51 | + f"About {APP_NAME}", |
| 52 | + f"{APP_NAME} v{APP_VERSION}\n\n" |
| 53 | + "Professional Screen Capture Tool\n\n" |
| 54 | + "Features:\n" |
| 55 | + "• Full screen capture\n" |
| 56 | + "• Region capture\n" |
| 57 | + "• Delayed screenshots\n" |
| 58 | + "• Custom output folder\n" |
| 59 | + "• Progress tracking\n" |
| 60 | + "• Processing log\n\n" |
| 61 | + "Built with Python + Tkinter + ttkbootstrap\n" |
| 62 | + "© 2026 Mate Technologies\n" |
| 63 | + ) |
| 64 | + |
| 65 | + |
| 66 | +# =================== MENU =================== |
| 67 | + |
| 68 | +menubar = tb.Menu(app) |
| 69 | + |
| 70 | +help_menu = tb.Menu(menubar, tearoff=0) |
| 71 | +help_menu.add_command(label="About", command=show_about) |
| 72 | + |
| 73 | +menubar.add_cascade(label="Help", menu=help_menu) |
| 74 | + |
| 75 | +app.config(menu=menubar) |
| 76 | + |
| 77 | + |
| 78 | +# =================== FLAGS =================== |
| 79 | + |
| 80 | +stop_flag = False |
| 81 | +pause_flag = False |
| 82 | + |
| 83 | +ui_queue = Queue() |
| 84 | + |
| 85 | +output_path = tb.StringVar(value=os.getcwd()) |
| 86 | +delay_seconds = tb.IntVar(value=0) |
| 87 | + |
| 88 | + |
| 89 | +# =================== TITLE =================== |
| 90 | + |
| 91 | +tb.Label( |
| 92 | + app, |
| 93 | + text=APP_NAME, |
| 94 | + font=("Segoe UI", 24, "bold") |
| 95 | +).pack(pady=(10, 2)) |
| 96 | + |
| 97 | +tb.Label( |
| 98 | + app, |
| 99 | + text="Professional Screen Capture Tool", |
| 100 | + font=("Segoe UI", 10, "italic"), |
| 101 | + foreground="#9ca3af" |
| 102 | +).pack(pady=(0, 10)) |
| 103 | + |
| 104 | + |
| 105 | +# =================== FRAME: CAPTURE CONTROLS =================== |
| 106 | + |
| 107 | +frame1 = tb.Labelframe(app, text="Capture Controls", padding=10) |
| 108 | +frame1.pack(fill="x", padx=10, pady=6) |
| 109 | + |
| 110 | + |
| 111 | +# Delay |
| 112 | + |
| 113 | +tb.Label(frame1, text="Delay (seconds):").pack(side="left") |
| 114 | + |
| 115 | +delay_entry = tb.Entry(frame1, textvariable=delay_seconds, width=6) |
| 116 | +delay_entry.pack(side="left", padx=5) |
| 117 | + |
| 118 | + |
| 119 | +# Output Folder |
| 120 | + |
| 121 | +tb.Label(frame1, text="Output Folder:", width=13).pack(side="left", padx=(20, 0)) |
| 122 | + |
| 123 | +tb.Entry(frame1, textvariable=output_path, width=40).pack(side="left", padx=6) |
| 124 | + |
| 125 | + |
| 126 | +def browse_output(): |
| 127 | + folder = filedialog.askdirectory() |
| 128 | + if folder: |
| 129 | + output_path.set(folder) |
| 130 | + |
| 131 | + |
| 132 | +tb.Button(frame1, text="Browse", command=browse_output).pack(side="left", padx=4) |
| 133 | + |
| 134 | + |
| 135 | +# =================== SCREENSHOT FUNCTIONS =================== |
| 136 | + |
| 137 | +def capture_fullscreen(): |
| 138 | + |
| 139 | + try: |
| 140 | + |
| 141 | + if delay_seconds.get() > 0: |
| 142 | + ui_queue.put(("log", f"Waiting {delay_seconds.get()} seconds...")) |
| 143 | + time.sleep(delay_seconds.get()) |
| 144 | + |
| 145 | + img = ImageGrab.grab() |
| 146 | + |
| 147 | + file_name = f"screenshot_{int(time.time())}.png" |
| 148 | + |
| 149 | + path = os.path.join(output_path.get(), file_name) |
| 150 | + |
| 151 | + img.save(path) |
| 152 | + |
| 153 | + ui_queue.put(("log", f"✔ Saved: {file_name}")) |
| 154 | + |
| 155 | + except Exception: |
| 156 | + log_error() |
| 157 | + ui_queue.put(("log", "❌ Screenshot failed")) |
| 158 | + |
| 159 | + ui_queue.put(("progress", 100)) |
| 160 | + |
| 161 | + |
| 162 | +# =================== REGION CAPTURE =================== |
| 163 | + |
| 164 | +def capture_region(): |
| 165 | + |
| 166 | + selector = tk.Toplevel() |
| 167 | + selector.attributes("-fullscreen", True) |
| 168 | + selector.attributes("-alpha", 0.3) |
| 169 | + selector.configure(bg="black") |
| 170 | + |
| 171 | + canvas = tk.Canvas(selector, cursor="cross", bg="black") |
| 172 | + canvas.pack(fill="both", expand=True) |
| 173 | + |
| 174 | + start_x = start_y = 0 |
| 175 | + rect = None |
| 176 | + |
| 177 | + def on_press(event): |
| 178 | + nonlocal start_x, start_y, rect |
| 179 | + start_x = event.x |
| 180 | + start_y = event.y |
| 181 | + rect = canvas.create_rectangle(start_x, start_y, start_x, start_y, outline="red", width=2) |
| 182 | + |
| 183 | + def on_drag(event): |
| 184 | + canvas.coords(rect, start_x, start_y, event.x, event.y) |
| 185 | + |
| 186 | + def on_release(event): |
| 187 | + |
| 188 | + x1 = min(start_x, event.x) |
| 189 | + y1 = min(start_y, event.y) |
| 190 | + x2 = max(start_x, event.x) |
| 191 | + y2 = max(start_y, event.y) |
| 192 | + |
| 193 | + selector.destroy() |
| 194 | + |
| 195 | + try: |
| 196 | + |
| 197 | + img = ImageGrab.grab(bbox=(x1, y1, x2, y2)) |
| 198 | + |
| 199 | + file_name = f"screenshot_region_{int(time.time())}.png" |
| 200 | + |
| 201 | + path = os.path.join(output_path.get(), file_name) |
| 202 | + |
| 203 | + img.save(path) |
| 204 | + |
| 205 | + ui_queue.put(("log", f"✔ Region saved: {file_name}")) |
| 206 | + |
| 207 | + except: |
| 208 | + log_error() |
| 209 | + ui_queue.put(("log", "❌ Region capture failed")) |
| 210 | + |
| 211 | + ui_queue.put(("progress", 100)) |
| 212 | + |
| 213 | + canvas.bind("<ButtonPress-1>", on_press) |
| 214 | + canvas.bind("<B1-Motion>", on_drag) |
| 215 | + canvas.bind("<ButtonRelease-1>", on_release) |
| 216 | + |
| 217 | + |
| 218 | +# =================== THREAD STARTERS =================== |
| 219 | + |
| 220 | +def start_fullscreen(): |
| 221 | + progress_var.set(0) |
| 222 | + threading.Thread(target=capture_fullscreen, daemon=True).start() |
| 223 | + |
| 224 | + |
| 225 | +def start_region(): |
| 226 | + progress_var.set(0) |
| 227 | + capture_region() |
| 228 | + |
| 229 | + |
| 230 | +# =================== BUTTONS =================== |
| 231 | + |
| 232 | +tb.Button( |
| 233 | + frame1, |
| 234 | + text="📸 Full Screen", |
| 235 | + bootstyle="success", |
| 236 | + command=start_fullscreen |
| 237 | +).pack(side="left", padx=6) |
| 238 | + |
| 239 | +tb.Button( |
| 240 | + frame1, |
| 241 | + text="🖼 Capture Region", |
| 242 | + bootstyle="info", |
| 243 | + command=start_region |
| 244 | +).pack(side="left", padx=4) |
| 245 | + |
| 246 | + |
| 247 | +# =================== PROGRESS =================== |
| 248 | + |
| 249 | +frame2 = tb.Labelframe(app, text="Progress", padding=8) |
| 250 | +frame2.pack(fill="x", padx=10) |
| 251 | + |
| 252 | +progress_var = tb.IntVar() |
| 253 | + |
| 254 | +tb.Progressbar( |
| 255 | + frame2, |
| 256 | + variable=progress_var, |
| 257 | + maximum=100, |
| 258 | + length=400 |
| 259 | +).pack(side="left", padx=10) |
| 260 | + |
| 261 | +status_lbl = tb.Label(frame2, text="Status: Ready") |
| 262 | +status_lbl.pack(side="left", padx=10) |
| 263 | + |
| 264 | + |
| 265 | +# =================== LOG =================== |
| 266 | + |
| 267 | +frame3 = tb.Labelframe(app, text="Processing Log", padding=8) |
| 268 | +frame3.pack(fill="both", expand=True, padx=10, pady=6) |
| 269 | + |
| 270 | +log_text = tk.Text(frame3, height=10) |
| 271 | +log_text.pack(side="left", fill="both", expand=True) |
| 272 | + |
| 273 | +scroll = tk.Scrollbar(frame3, command=log_text.yview) |
| 274 | +scroll.pack(side="right", fill="y") |
| 275 | + |
| 276 | +log_text.config(yscrollcommand=scroll.set, state="disabled") |
| 277 | + |
| 278 | + |
| 279 | +# =================== UI QUEUE =================== |
| 280 | + |
| 281 | +def process_ui_queue(): |
| 282 | + |
| 283 | + try: |
| 284 | + |
| 285 | + while True: |
| 286 | + |
| 287 | + cmd, data = ui_queue.get_nowait() |
| 288 | + |
| 289 | + if cmd == "progress": |
| 290 | + |
| 291 | + progress_var.set(data) |
| 292 | + |
| 293 | + elif cmd == "log": |
| 294 | + |
| 295 | + log_text.config(state="normal") |
| 296 | + log_text.insert("end", data + "\n") |
| 297 | + log_text.see("end") |
| 298 | + log_text.config(state="disabled") |
| 299 | + |
| 300 | + elif cmd == "status": |
| 301 | + |
| 302 | + status_lbl.config(text=f"Status: {data}") |
| 303 | + |
| 304 | + except Empty: |
| 305 | + pass |
| 306 | + |
| 307 | + app.after(100, process_ui_queue) |
| 308 | + |
| 309 | + |
| 310 | +# =================== START UI =================== |
| 311 | + |
| 312 | +app.after(100, process_ui_queue) |
| 313 | + |
| 314 | +app.mainloop() |
0 commit comments