-
Notifications
You must be signed in to change notification settings - Fork 0
/
annotation2.py
39 lines (29 loc) · 1.19 KB
/
annotation2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import tkinter as tk
import pyscreenshot as ImageGrab
from PIL import Image, ImageTk
class SnippingToolApp:
def __init__(self, root):
self.root = root
self.root.title("Snipping Tool")
self.snip_button = tk.Button(root, text="Capture Snip", command=self.capture_snip)
self.snip_button.pack(pady=10)
self.canvas = tk.Canvas(root)
self.canvas.pack()
self.start_x = self.start_y = self.end_x = self.end_y = None
def capture_snip(self):
self.root.withdraw() # Hide the main window temporarily
snip = ImageGrab.grab(bbox=(0, 0, 1920, 1080)) # Capture the screen
# Create a new window to display the snip
snip_window = tk.Toplevel()
snip_window.title("Snip")
snip_tk = ImageTk.PhotoImage(snip)
snip_label = tk.Label(snip_window, image=snip_tk)
snip_label.pack()
snip_window.protocol("WM_DELETE_WINDOW", lambda: self.on_snip_close(snip_window))
def on_snip_close(self, snip_window):
self.root.deiconify() # Show the main window again
snip_window.destroy()
if __name__ == "__main__":
root = tk.Tk()
app = SnippingToolApp(root)
root.mainloop()