[Python] Tkinter invokes wm command when window destroyed after CTkMessagebox used

Discussão em 'Python' iniciado por Stack, Junho 25, 2025.

  1. Stack

    Stack Membro Participativo

    My application uses CustomTkinter and reads data on start up:

    import customtkinter as ctk
    from CTkMessagebox import CTkMessagebox


    class App(ctk.CTk):
    def __init__(self) -> None:
    super().__init__()
    self.wnd_root = ctk.CTk()
    self.after_idle(self.on_startup)

    def on_startup(self) -> None:
    # Load required data here, assume it fails
    mbox = CTkMessagebox()
    self.wait_window(mbox)
    self.destroy()


    if __name__ == '__main__':
    app = App()
    app.mainloop()


    If this fails it outputs a message box and waits for it to close then destroys the window.

    This throws a "TclError: can't invoke "wm" command: application has been destroyed" error:

    invalid command name "2759755045376check_dpi_scaling"
    while executing
    "2759755045376check_dpi_scaling"
    ("after" script)
    invalid command name "2759665803776update"
    while executing
    "2759665803776update"
    ("after" script)
    Traceback (most recent call last):
    File "C:\Users\danie\PycharmProjects\THCompetencyTracker\source\close_test.py", line 20, in <module>
    app.mainloop()
    File "C:\Users\danie\PycharmProjects\THCompetencyTracker\.venv\Lib\site-packages\customtkinter\windows\ctk_tk.py", line 157, in mainloop
    self._windows_set_titlebar_color(self._get_appearance_mode())
    File "C:\Users\danie\PycharmProjects\THCompetencyTracker\.venv\Lib\site-packages\customtkinter\windows\ctk_tk.py", line 319, in _windows_set_titlebar_color
    self.state(self._state_before_windows_set_titlebar_color) # other states
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\danie\AppData\Local\Programs\Python\Python312\Lib\tkinter\__init__.py", line 2290, in wm_state
    return self.tk.call('wm', 'state', self._w, newstate)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    _tkinter.TclError: can't invoke "wm" command: application has been destroyed
    can't invoke "winfo" command: application has been destroyed


    Any help?

    Continue reading...

Compartilhe esta Página