Replies: 1 comment
|
Your file is called gui_threaded, and that's the whole problem: you're updating widgets from a background thread. Tkinter can only be touched from the main thread (the one running mainloop). When a thread changes a widget, it corrupts Tkinter's internals at random moments — which is exactly why the crash is unpredictable, and why you see both "invalid command name" and the weird UnicodeDecodeError. Rule: do the heavy work in the thread, but never call a widget from it. Send the result back to the main thread instead. The simplest fix is to wrap every widget update in self.after(0, ...) so it runs on the main thread. So instead of calling self.progress_label.configure(text=value) directly from the worker thread, call it like this: self.after(0, lambda: self.progress_label.configure(text=value)) after(0, ...) is safe to call from a thread; it just schedules the update to run on the GUI thread. One more thing: when you close the window, cancel any pending after jobs so a late callback doesn't fire on a widget that's already gone: self.after_cancel(self._job_id) Move all widget changes behind after(), and the random crashes stop. |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
The main issue I am facing with this error (image) is its randomness, as I can't seem to catch how and when it pops up and kills the whole application. Sometimes it appears, and sometimes it doesn't. Hope you can help me!
this is the associated error in terminal:
I am trying to build a GUI that has the following:
that's what I remember for the moment, but i am happy to cooperate to figure this out.
Thank you,
All reactions