0

I have a single global check_label(tkinter label) that is modified with a separate function that is on a daemon thread so that it is always running while the program is. When I close the window using the X button I do not get any warnings. However, when I close the window using root.destroy() I get the warning below(it doesn't cause an issue, everything works correctly). Can someone explain the difference between root.destroy() and the X button or shed some light on why this would happen only when using root.destroy? Below is the code I am using.

def check_working_thread():
    run_thread = threading.Thread(target=check_working)
    run_thread.daemon = True
    run_thread.start()


def check_working():
    while True:
        working = "path_to_server_is_here"
        lines_seen = []

        with open(working, "r") as n:
            for each_line in n.read().split("{}"):
                if each_line not in lines_seen:
                    lines_seen.append(each_line)
                    employees_working = "".join(lines_seen)
                    check_label["text"] = employees_working
                    n.close()

The warning I see is as follows:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Users\Rory Moore\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in _bootstrap_inner
    self.run()
  File "C:\Users\Rory Moore\AppData\Local\Programs\Python\Python39\lib\threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Programming_Projects\MT_TimeClock\TimeClock.py", line 598, in check_working
    check_label["text"] = employees_working
  File "C:\Users\Rory Moore\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1657, in __setitem__
    self.configure({key: value})
  File "C:\Users\Rory Moore\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1646, in configure
    return self._configure('configure', cnf, kw)
  File "C:\Users\Rory Moore\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1636, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name ".!frame3.!label2"

Process finished with exit code 0
Rory
  • 430
  • 2
  • 8
  • 1
    I think what [`root.destroy` does](https://stackoverflow.com/a/42928131/13382000) will give you more light. Basically the error says that even after the window is _destroyed_ your widget is still trying to be accessed – Delrius Euphoria Apr 06 '22 at 20:22
  • That clarified it. Changing it to root.quit() eliminates that warning. – Rory Apr 06 '22 at 22:38

0 Answers0