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.