TomSchimansky / CustomTkinter

A modern and customizable python UI-library based on Tkinter
MIT License
11.64k stars 1.09k forks source link

tkinter window randomly appearing #2505

Closed Ricc4rdo0107 closed 4 months ago

Ricc4rdo0107 commented 4 months ago

Using this class, that I built just for fun, somehow creates another white tkinter window customtkinter==5.2.2 python: 3.12

class CTkInputPopup(ctk.CTkToplevel):
    def __init__(self, title: str, text: str, centered: bool=False, *args,  fg_color: str | Tuple[str] | None = None, **kwargs):
        super().__init__(*args, fg_color=fg_color, **kwargs)
        self._text = text
        self._title = title

        self.title(self._title)

        self.lift()
        self.attributes("-topmost", True)
        #self.protocol("WM_DELETE_WINDOW", lambda x: None)
        if centered:
            screen_size = self.winfo_screenwidth(), self.winfo_screenheight()
            x, y = screen_size[0]//2, screen_size[1]//2
            self.geometry("%d+%d" % (x, y))

        self.after(10, self._create_widgets)
        self.resizable(False, False)
        self.grab_set()

    def _on_exit(self, event):
        self._input = self._entry.get().strip()
        self.destroy()

    def _create_widgets(self):
        self._label = ctk.CTkLabel(self, text=self._text)
        self._entry = ctk.CTkEntry(self)

        self._label.pack(fill="x", expand=1, padx=12, pady=12)
        self._entry.pack(fill="x", expand=1, padx=12, pady=12)
        self._entry.bind("<Return>", self._on_exit)

    def get_input(self):
        self.wait_window()
        return self._input