From 3ae2fe09de4666c258f6373aa28e181085958349 Mon Sep 17 00:00:00 2001 From: ATATC Date: Wed, 11 Dec 2024 19:59:52 -0500 Subject: [PATCH] Bug fixed: the callbacks attached to the variable that remain after the widget is destroyed cause errors that it cannot find the widget. (#456) --- leads_gui/prototype.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/leads_gui/prototype.py b/leads_gui/prototype.py index 9bafee5..f88553d 100644 --- a/leads_gui/prototype.py +++ b/leads_gui/prototype.py @@ -1,7 +1,7 @@ from abc import ABCMeta as _ABCMeta, abstractmethod as _abstractmethod from json import dumps as _dumps from time import time as _time -from tkinter import Misc as _Misc, Event as _Event, PhotoImage as _PhotoImage +from tkinter import Misc as _Misc, Event as _Event, PhotoImage as _PhotoImage, TclError as _TclError from typing import Callable as _Callable, Self as _Self, TypeVar as _TypeVar, Generic as _Generic, Any as _Any, \ Literal as _Literal, override as _override @@ -173,7 +173,10 @@ def attach(self, callback: _Callable[[], None]) -> None: def unique(_, __, ___) -> None: if (v := self._variable.get()) != self._last_value: - callback() + try: + callback() + except _TclError: + self.detach() self._last_value = v self._trace_cb_name = self._variable.trace_add("write", unique)