Skip to content

Commit

Permalink
Bug fixed: the callbacks attached to the variable that remain after t…
Browse files Browse the repository at this point in the history
…he widget is destroyed cause errors that it cannot find the widget. (#456)
  • Loading branch information
ATATC committed Dec 12, 2024
1 parent 1169766 commit 3ae2fe0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions leads_gui/prototype.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3ae2fe0

Please sign in to comment.