tkinter.TclError: invalid command name ".!toplevel.!label7"

Viewed 21

I have written a tKinter application for a Raspberry Pi. I have a main screen and four Toplevel windows that are activated by buttons on the main window. Each Toplevel window has a “Return to Maine Menu” button that destroys the Toplevel window so that the main window is displayed. One of the Toplevel windows calls a recursive function that polls sensors attached to the Raspberry Pi and displays the data from those sensors on the screen. The recursive function repeats ever second. When I click the “Return to Main Menu” button on this Toplevel window, the window closes, but I get the following error message stream:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.9/tkinter/__init__.py", line 1892, in __call__
    return self.func(*args)
  File "/usr/lib/python3.9/tkinter/__init__.py", line 814, in callit
    func(*args)
  File "/home/pi/Old_Marsh_Module.3.py", line 171, in Refresher
    lps5.configure(image = BP1_on_off)
  File "/usr/lib/python3.9/tkinter/__init__.py", line 1646, in configure
    return self._configure('configure', cnf, kw)
  File "/usr/lib/python3.9/tkinter/__init__.py", line 1636, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name ".!toplevel.!label7"

From what I have been able to find on this and other websites, the problem seems to be caused when the window closes while the recursive function is still running. Is there a way to stop the recursive finction before the tK inter Toplevel window is destroyed?

0 Answers
Related