实现截图和贴图以及简单绘图的基本功能

This commit is contained in:
awin-x 2025-01-15 20:19:00 +08:00
parent 8e58179538
commit 67b54ce2b6

View File

@ -9,6 +9,7 @@ import threading
class PinPicture(tk.Frame):
def __init__(self, image, master=None):
super().__init__(master)
self.pinBtn = None
self.lineBtn = None
self.arrowBtn = None
self.rectBtn = None
@ -51,6 +52,7 @@ class PinPicture(tk.Frame):
self.rectBtn = tk.Button(text='矩形', command=self.set_rect)
self.arrowBtn = tk.Button(text='箭头', command=self.set_arrow)
self.lineBtn = tk.Button(text='直线', command=self.set_line)
self.pinBtn = tk.Button(text='确定', command=self.pin_mode_event)
self.master.bind("<Escape>", self.close)
self.master.bind("<Enter>", self.enter_canvas)
@ -99,6 +101,13 @@ class PinPicture(tk.Frame):
self.canvas.bind("<ButtonPress-1>", self.on_drag_start)
self.canvas.bind("<B1-Motion>", self.on_drag)
self.canvas.bind("<MouseWheel>", self.on_mouse_wheel)
if self.drawMode:
self.drawMode = False
self.pinBtn.pack_forget()
self.lineBtn.pack_forget()
self.arrowBtn.pack_forget()
self.penBtn.pack_forget()
self.rectBtn.pack_forget()
# 鼠标进入
def enter_canvas(self, event):
@ -123,6 +132,7 @@ class PinPicture(tk.Frame):
self.rectBtn.pack()
self.arrowBtn.pack()
self.lineBtn.pack()
self.pinBtn.pack()
def set_pen(self):
self.canvas.bind("<B1-Motion>", self.pen)
@ -163,6 +173,7 @@ class PinPicture(tk.Frame):
self.drawPad = ImageDraw.Draw(self.pad)
self.penX = event.x
self.penY = event.y
# 关闭窗口
def close(self, event):
self.master.destroy()
@ -247,10 +258,9 @@ class PinPicture(tk.Frame):
y1 = pos[1]
x2 = pos[2]
y2 = pos[3]
l = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
l = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) + 1
cosa = (x2 - x1) / l
sina = (y2 - y1) / l
k = sina / cosa
d = self.arrowSize * (sina + cosa)
if (sina < cosa):
xa = x2 - d