CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

Customtkinter destroy

Open galipyuksel opened this issue 2 years ago • 0 comments

After the self.destroy() code is activated, something appears on the console as in the picture. What is this? image

galipyuksel avatar Aug 09 '22 07:08 galipyuksel

it's pointing the same log in my project🤔

Jdsdofp avatar Aug 16 '22 00:08 Jdsdofp

Here too, same message...

luisotaviocintra avatar Aug 16 '22 13:08 luisotaviocintra

@galipyuksel can you post an example code where this appears for you?

TomSchimansky avatar Aug 16 '22 17:08 TomSchimansky

link for the code: https://github.com/Aadhityaa04/Customtkinter-destroy---error/blob/2fa951752cbc9e26819997b1ef0e596a96fbcb77/playgrund.py Screenshot 2022-09-04 110957 while clicking login button you will get the error. Maybe in line 25.

Aadhityaa04 avatar Sep 04 '22 05:09 Aadhityaa04

Your link is broken.

PosthumasFrankestein avatar Sep 05 '22 06:09 PosthumasFrankestein

Sorry for the inconveniences Click this

Aadhityaa04 avatar Sep 05 '22 15:09 Aadhityaa04

This error is caused due to "after" jobs that have already been scheduled running but since the window has been destroyed it can't find those jobs. You should look at CTkToplevel to create new window.

PosthumasFrankestein avatar Sep 06 '22 11:09 PosthumasFrankestein

@Aadhityaa04 you can not create multiple instances of CTk in the same process. Here is an example on how you would create a second window, which can only be opened once and which is written as a class:

import customtkinter


class ToplevelWindow(customtkinter.CTkToplevel):
    def __init__(self, *args, closing_event=None, **kwargs):
        super().__init__(*args, **kwargs)
        self.protocol("WM_DELETE_WINDOW", self.closing)
        self.geometry("500x300")
        self.closing_event = closing_event

        self.label = customtkinter.CTkLabel(self, text="ToplevelWindow")
        self.label.pack(padx=20, pady=20)

    def closing(self):
        self.destroy()
        if self.closing_event is not None:
            self.closing_event()


class App(customtkinter.CTk):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.geometry("500x400")

        self.button_1 = customtkinter.CTkButton(self, text="Open CTkToplevel", command=self.open_toplevel)
        self.button_1.pack(side="top", padx=40, pady=40)

        self.toplevel_window = None

    def open_toplevel(self):
        if self.toplevel_window is None:  # create toplevel window only if not already open
            self.toplevel_window = ToplevelWindow(self, closing_event=self.toplevel_close_event)

    def toplevel_close_event(self):
        self.toplevel_window = None


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

If you follow this template there shouldn't be any invalid command name logs. Personally I never experienced them...

TomSchimansky avatar Sep 13 '22 20:09 TomSchimansky