TomSchimansky / CustomTkinter

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

CTkOptionMenu & CTkComboBox throw error during display scale change after being destroyed #2584

Open Franzyd opened 1 month ago

Franzyd commented 1 month ago

Tested on Windows 10 The two dropdown menu widgets, CTkOptionMenu and CTkComboBox throw a TcLError: invalid command name when the window's scale changes after being destroyed. Tested scenarios are changing the display scale in Windows settings and moving it to another monitor with a different display scale.

import customtkinter

app = customtkinter.CTk()
app.geometry("400x150")

options = customtkinter.CTkOptionMenu(app, values=["1", "2", "3"])
options.pack() //layout manager is irrelevant

delete = customtkinter.CTkButton(app, text="Delete", command= lambda: options.destroy())
delete.pack()

app.mainloop()

Clicking the button to destroy the dropdown widget and then changing the display scale throws:

File "C:\Python312\Lib\tkinter\__init__.py", line 1962, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\tkinter\__init__.py", line 861, in callit
    func(*args)
  File "C:\Python312\Lib\site-packages\customtkinter\windows\widgets\scaling\scaling_tracker.py", line 187, in check_dpi_scaling
    cls.update_scaling_callbacks_for_window(window)
  File "C:\Python312\Lib\site-packages\customtkinter\windows\widgets\scaling\scaling_tracker.py", line 64, in update_scaling_callbacks_for_window    
  File "C:\Python312\Lib\site-packages\customtkinter\windows\widgets\core_widget_classes\dropdown_menu.py", line 193, in _set_scaling
    self._configure_menu_for_platforms()
  File "C:\Python312\Lib\site-packages\customtkinter\windows\widgets\core_widget_classes\dropdown_menu.py", line 66, in _configure_menu_for_platforms    super().configure(tearoff=False,
  File "C:\Python312\Lib\tkinter\__init__.py", line 1716, in configure
    return self._configure('configure', cnf, kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\tkinter\__init__.py", line 1706, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name ".!ctkcombobox.!dropdownmenu"

After that the window is still interactable but semitransparent and doesn't rescale anymore: image

dipeshSam commented 1 month ago

Did you try any workaround to fix this?

Franzyd commented 1 month ago

@dipeshSam unfortunately I haven't