1

I'm am using a mix of customtkinter and tkinter to program my software, based on MVC architecture. However, when quitting using the regular [x] button, I have the following error repeated mutliple times for different lambdas:

    while executing
"140292574995648"
    (command for "WM_DELETE_WINDOW" window manager protocol)
invalid command name "140292575264640update"
    while executing
"140292575264640update"
    ("after" script)

And even though my tkapp closes, the Python interpreter of PyCharm still runs.

I read in this first post and in this second post that it has to do with the destroy() method when there are after() statements used after the destruction of the main root, coupled with the fact that to cite the second post, customtkinter uses the after command to handle the animation of the button. However, in between the button being pressed and released you're destroying the root window. That makes it impossible for the after command to run since it has been destroyed.

Here is a sample of my code:

from functools import partial

import customtkinter

import params
from VIEW.MainView import MainView

class App(customtkinter.CTk):
    def __init__(self):
        super().__init__()
        self.withdraw()
        self.title(f'FireLearn GUI v{params.version}')
        view = MainView(self)
        self.after(0, self.deiconify)


def onClosure(app):
    app.quit()
    exit()


if __name__ == '__main__':
    app = App()
    app.protocol('WM_DELETE_WINDOW', partial(onClosure, app))  # root is your root window
    app.mainloop()

knowing that the after() called in the init() is the only one I wrote in my whole code and doesn't change much when removed.

I tried to avoid using destroy() by handling the closure by first using quit() to close the app, then exit() to end all the remaining processes, in my onClosure() function. This works fine.

But am I 'in the right' to do this ? Is it bad practice ? Am I missing some important sub-process or killing processes in a bad way doing so ? I'd like to do things upright.

Thanks for the help.

Thingamabobs
  • 7,274
  • 5
  • 21
  • 54
Willy Lutz
  • 134
  • 1
  • 1
  • 9
  • Maybe [reading this](https://stackoverflow.com/questions/2307464/what-is-the-difference-between-root-destroy-and-root-quit) will be of some help. – Rory Aug 04 '23 at 13:26
  • Try using a bigger number than 0. 0 places the task immediately as the next job and in case of an error there will be no time to cancel the job. A good value is around 50 ms and there should be barley a case in a GUI process where you need a faster execution. – Thingamabobs Aug 05 '23 at 22:44
  • the `after` called here is only used at the creation of the view, so it does not do much to increase the value to 50 on the destruction of the window. However I keep this advice for another time thanks. – Willy Lutz Aug 07 '23 at 08:15

0 Answers0