added additional force_focus call for CTk and CTkToplevel on macOS to fix bug where window disappears when window is selected from Mission Control

This commit is contained in:
Tom Schimansky 2022-10-14 19:26:16 +02:00
parent 5977dcbaeb
commit 362fcbaf13
2 changed files with 12 additions and 0 deletions

View File

@ -67,9 +67,15 @@ class CTk(tkinter.Tk):
self._windows_set_titlebar_color("light") self._windows_set_titlebar_color("light")
self.bind('<Configure>', self._update_dimensions_event) self.bind('<Configure>', self._update_dimensions_event)
self.bind('<FocusIn>', self._focus_in_event)
self._block_update_dimensions_event = False self._block_update_dimensions_event = False
def _focus_in_event(self, event):
# sometimes window looses focus on macOS if window is selected from Mission Control, so focus has to be forced again
if sys.platform == "darwin":
self.focus_force()
def _update_dimensions_event(self, event=None): def _update_dimensions_event(self, event=None):
if not self._block_update_dimensions_event: if not self._block_update_dimensions_event:
detected_width = self.winfo_width() # detect current window size detected_width = self.winfo_width() # detect current window size

View File

@ -63,6 +63,12 @@ class CTkToplevel(tkinter.Toplevel):
self._windows_set_titlebar_color("light") self._windows_set_titlebar_color("light")
self.bind('<Configure>', self._update_dimensions_event) self.bind('<Configure>', self._update_dimensions_event)
self.bind('<FocusIn>', self._focus_in_event)
def _focus_in_event(self, event):
# sometimes window looses focus on macOS if window is selected from Mission Control, so focus has to be forced again
if sys.platform == "darwin":
self.focus_force()
def _update_dimensions_event(self, event=None): def _update_dimensions_event(self, event=None):
detected_width = self.winfo_width() # detect current window size detected_width = self.winfo_width() # detect current window size