小bug修改

This commit is contained in:
Ray
2025-11-01 16:32:07 +08:00
parent 069613fe09
commit 4a0549114f
2 changed files with 6 additions and 2 deletions

View File

@@ -67,7 +67,7 @@ def create_launcher():
# 说明 # 说明
info_label = tk.Label(root, info_label = tk.Label(root,
text="提示:首次使用请先点击"配置管理"设置参数", text="提示:首次使用请先点击配置管理设置参数",
font=('Arial', 9), font=('Arial', 9),
fg='gray') fg='gray')
info_label.pack(side=tk.BOTTOM, pady=10) info_label.pack(side=tk.BOTTOM, pady=10)

View File

@@ -283,6 +283,7 @@ class PreviewWindow:
photo = ImageTk.PhotoImage(image=pil_image) photo = ImageTk.PhotoImage(image=pil_image)
# 保持引用避免被GC # 保持引用避免被GC
self.photo_objects[idx] = photo self.photo_objects[idx] = photo
self._grid_photos.append(photo)
images_to_draw.append((photo, center_x, center_y)) images_to_draw.append((photo, center_x, center_y))
texts_to_draw.append((center_x, y + 15, name, 'white')) texts_to_draw.append((center_x, y + 15, name, 'white'))
@@ -416,6 +417,8 @@ class PreviewWindow:
canvas.pack(fill=tk.BOTH, expand=True) canvas.pack(fill=tk.BOTH, expand=True)
photo_obj = {} photo_obj = {}
# 持久引用大窗当前帧 PhotoImage避免GC
self._large_photos = []
def update_large_once(): def update_large_once():
if not self.running or not self.large_window.winfo_exists(): if not self.running or not self.large_window.winfo_exists():
@@ -441,8 +444,9 @@ class PreviewWindow:
resized_frame = cv2.cvtColor(resized_frame, cv2.COLOR_BGR2RGB) resized_frame = cv2.cvtColor(resized_frame, cv2.COLOR_BGR2RGB)
pil_image = Image.fromarray(resized_frame) pil_image = Image.fromarray(resized_frame)
photo = ImageTk.PhotoImage(image=pil_image) photo = ImageTk.PhotoImage(image=pil_image)
# 保存引用到字典确保不被GC # 保存引用到字典和列表确保不被GC
photo_obj['img'] = photo photo_obj['img'] = photo
self._large_photos = [photo]
# 清空并绘制新图像 # 清空并绘制新图像
canvas.delete("all") canvas.delete("all")