Update ui.py

Added:
- try-finally Block: This makes sure the camera.release() is called no matter how the while loops end.
- Resource Cleanup: The finally block takes care of cleaning up resources to keep the application stable.
pull/868/head
Makaru 2025-01-05 20:19:36 +08:00 committed by GitHub
parent 22940d1b99
commit 742bcab130
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 58 additions and 56 deletions

View File

@ -795,6 +795,7 @@ def create_webcam_preview(camera_index: int):
frame_count = 0
fps = 0
try:
while camera:
ret, frame = camera.read()
if not ret:
@ -860,11 +861,12 @@ def create_webcam_preview(camera_index: int):
if PREVIEW.state() == "withdrawn":
break
finally:
camera.release()
PREVIEW.withdraw()
def create_source_target_popup_for_webcam(
root: ctk.CTk, map: list, camera_index: int
) -> None: