2021-12-31 21:07:53 +03:00
|
|
|
import tkinter
|
|
|
|
from distutils.version import StrictVersion as Version
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import platform
|
2022-02-17 18:39:39 +03:00
|
|
|
import ctypes
|
2022-11-11 01:27:55 +03:00
|
|
|
from typing import Union, Tuple, Optional
|
2021-12-31 21:07:53 +03:00
|
|
|
|
2022-11-29 21:06:33 +03:00
|
|
|
from .widgets.theme import ThemeManager
|
|
|
|
from .widgets.scaling import CTkScalingBaseClass
|
|
|
|
from .widgets.appearance_mode import CTkAppearanceModeBaseClass
|
2021-12-31 21:07:53 +03:00
|
|
|
|
2022-11-29 21:06:33 +03:00
|
|
|
from customtkinter.windows.widgets.utility.utility_functions import pop_from_dict_by_set, check_kwargs_empty
|
2022-10-16 21:13:19 +03:00
|
|
|
|
2021-12-31 21:07:53 +03:00
|
|
|
|
2022-10-29 14:11:55 +03:00
|
|
|
class CTk(tkinter.Tk, CTkAppearanceModeBaseClass, CTkScalingBaseClass):
|
2022-10-02 04:23:10 +03:00
|
|
|
"""
|
|
|
|
Main app window with dark titlebar on Windows and macOS.
|
|
|
|
For detailed information check out the documentation.
|
|
|
|
"""
|
|
|
|
|
2022-11-11 01:27:55 +03:00
|
|
|
_valid_tk_constructor_arguments: set = {"screenName", "baseName", "className", "useTk", "sync", "use"}
|
2022-10-16 21:13:19 +03:00
|
|
|
|
2022-11-11 01:27:55 +03:00
|
|
|
_valid_tk_configure_arguments: set = {'bd', 'borderwidth', 'class', 'menu', 'relief', 'screen',
|
|
|
|
'use', 'container', 'cursor', 'height',
|
|
|
|
'highlightthickness', 'padx', 'pady', 'takefocus', 'visual', 'width'}
|
2022-10-16 21:13:19 +03:00
|
|
|
|
2022-11-11 01:27:55 +03:00
|
|
|
_deactivate_macos_window_header_manipulation: bool = False
|
|
|
|
_deactivate_windows_window_header_manipulation: bool = False
|
2022-10-22 15:24:04 +03:00
|
|
|
|
2022-10-16 21:13:19 +03:00
|
|
|
def __init__(self,
|
2022-11-11 01:27:55 +03:00
|
|
|
fg_color: Optional[Union[str, Tuple[str, str]]] = None,
|
2021-12-31 21:07:53 +03:00
|
|
|
**kwargs):
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._enable_macos_dark_title_bar()
|
2022-05-02 00:29:14 +03:00
|
|
|
|
2022-10-29 14:11:55 +03:00
|
|
|
# call init methods of super classes
|
|
|
|
tkinter.Tk.__init__(self, **pop_from_dict_by_set(kwargs, self._valid_tk_constructor_arguments))
|
|
|
|
CTkAppearanceModeBaseClass.__init__(self)
|
|
|
|
CTkScalingBaseClass.__init__(self, scaling_type="window")
|
2022-10-16 21:13:19 +03:00
|
|
|
check_kwargs_empty(kwargs, raise_error=True)
|
2022-05-02 00:29:14 +03:00
|
|
|
|
2022-10-29 14:11:55 +03:00
|
|
|
self._current_width = 600 # initial window size, independent of scaling
|
2022-10-02 04:23:10 +03:00
|
|
|
self._current_height = 500
|
|
|
|
self._min_width: int = 0
|
|
|
|
self._min_height: int = 0
|
|
|
|
self._max_width: int = 1_000_000
|
|
|
|
self._max_height: int = 1_000_000
|
|
|
|
self._last_resizable_args: Union[Tuple[list, dict], None] = None # (args, kwargs)
|
2022-05-02 00:29:14 +03:00
|
|
|
|
2022-11-27 04:48:09 +03:00
|
|
|
self._fg_color = ThemeManager.theme["CTk"]["fg_color"] if fg_color is None else self._check_color_type(fg_color)
|
2022-01-08 02:29:53 +03:00
|
|
|
|
2022-10-29 14:11:55 +03:00
|
|
|
# set bg of tkinter.Tk
|
2022-10-29 02:20:32 +03:00
|
|
|
super().configure(bg=self._apply_appearance_mode(self._fg_color))
|
2022-10-29 14:11:55 +03:00
|
|
|
|
2023-01-21 16:22:18 +03:00
|
|
|
# set title
|
2022-10-29 14:11:55 +03:00
|
|
|
self.title("CTk")
|
2021-12-31 21:07:53 +03:00
|
|
|
|
2023-01-21 16:22:18 +03:00
|
|
|
# indicator variables
|
|
|
|
self._iconbitmap_method_called = False # indicates if wm_iconbitmap method got called
|
2022-10-02 04:23:10 +03:00
|
|
|
self._state_before_windows_set_titlebar_color = None
|
|
|
|
self._window_exists = False # indicates if the window is already shown through update() or mainloop() after init
|
|
|
|
self._withdraw_called_before_window_exists = False # indicates if withdraw() was called before window is first shown through update() or mainloop()
|
|
|
|
self._iconify_called_before_window_exists = False # indicates if iconify() was called before window is first shown through update() or mainloop()
|
2023-01-21 16:22:18 +03:00
|
|
|
self._block_update_dimensions_event = False
|
|
|
|
|
2023-02-05 05:02:21 +03:00
|
|
|
# save focus before calling withdraw
|
|
|
|
self.focused_widget_before_widthdraw = None
|
|
|
|
|
2023-01-21 16:22:18 +03:00
|
|
|
# set CustomTkinter titlebar icon (Windows only)
|
|
|
|
if sys.platform.startswith("win"):
|
|
|
|
self.after(200, self._windows_set_titlebar_icon)
|
2022-02-18 16:33:45 +03:00
|
|
|
|
2023-01-21 16:22:18 +03:00
|
|
|
# set titlebar color (Windows only)
|
2022-02-17 18:39:39 +03:00
|
|
|
if sys.platform.startswith("win"):
|
2022-11-01 02:37:30 +03:00
|
|
|
self._windows_set_titlebar_color(self._get_appearance_mode())
|
2022-02-17 18:39:39 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self.bind('<Configure>', self._update_dimensions_event)
|
2022-10-14 20:26:16 +03:00
|
|
|
self.bind('<FocusIn>', self._focus_in_event)
|
2022-05-02 00:29:14 +03:00
|
|
|
|
2022-10-29 14:11:55 +03:00
|
|
|
def destroy(self):
|
|
|
|
self._disable_macos_dark_title_bar()
|
|
|
|
|
|
|
|
# call destroy methods of super classes
|
|
|
|
tkinter.Tk.destroy(self)
|
|
|
|
CTkAppearanceModeBaseClass.destroy(self)
|
|
|
|
CTkScalingBaseClass.destroy(self)
|
|
|
|
|
2022-10-14 20:26:16 +03:00
|
|
|
def _focus_in_event(self, event):
|
2022-10-22 02:20:08 +03:00
|
|
|
# sometimes window looses jumps back on macOS if window is selected from Mission Control, so has to be lifted again
|
2022-10-14 20:26:16 +03:00
|
|
|
if sys.platform == "darwin":
|
2022-10-22 02:20:08 +03:00
|
|
|
self.lift()
|
2022-10-14 20:26:16 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _update_dimensions_event(self, event=None):
|
|
|
|
if not self._block_update_dimensions_event:
|
2022-10-21 22:28:31 +03:00
|
|
|
|
2022-11-12 22:59:10 +03:00
|
|
|
detected_width = super().winfo_width() # detect current window size
|
|
|
|
detected_height = super().winfo_height()
|
2022-05-02 00:29:14 +03:00
|
|
|
|
2022-10-21 22:28:31 +03:00
|
|
|
# detected_width = event.width
|
|
|
|
# detected_height = event.height
|
|
|
|
|
2022-11-01 02:37:30 +03:00
|
|
|
if self._current_width != self._reverse_window_scaling(detected_width) or self._current_height != self._reverse_window_scaling(detected_height):
|
|
|
|
self._current_width = self._reverse_window_scaling(detected_width) # adjust current size according to new size given by event
|
|
|
|
self._current_height = self._reverse_window_scaling(detected_height) # _current_width and _current_height are independent of the scale
|
2022-05-02 00:29:14 +03:00
|
|
|
|
2022-10-22 16:42:22 +03:00
|
|
|
def _set_scaling(self, new_widget_scaling, new_window_scaling):
|
2022-11-01 02:37:30 +03:00
|
|
|
super()._set_scaling(new_widget_scaling, new_window_scaling)
|
2022-05-02 00:29:14 +03:00
|
|
|
|
2022-11-12 22:59:10 +03:00
|
|
|
# Force new dimensions on window by using min, max, and geometry. Without min, max it won't work.
|
2022-10-02 04:23:10 +03:00
|
|
|
super().minsize(self._apply_window_scaling(self._current_width), self._apply_window_scaling(self._current_height))
|
|
|
|
super().maxsize(self._apply_window_scaling(self._current_width), self._apply_window_scaling(self._current_height))
|
2022-10-15 02:02:54 +03:00
|
|
|
|
|
|
|
super().geometry(f"{self._apply_window_scaling(self._current_width)}x{self._apply_window_scaling(self._current_height)}")
|
2022-05-12 23:55:28 +03:00
|
|
|
|
2022-11-12 22:59:10 +03:00
|
|
|
# set new scaled min and max with delay (delay prevents weird bug where window dimensions snap to unscaled dimensions when mouse releases window)
|
|
|
|
self.after(1000, self._set_scaled_min_max) # Why 1000ms delay? Experience! (Everything tested on Windows 11)
|
2022-05-02 00:29:14 +03:00
|
|
|
|
2022-11-12 22:59:10 +03:00
|
|
|
def block_update_dimensions_event(self):
|
|
|
|
self._block_update_dimensions_event = False
|
|
|
|
|
|
|
|
def unblock_update_dimensions_event(self):
|
|
|
|
self._block_update_dimensions_event = False
|
2022-08-05 16:37:23 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _set_scaled_min_max(self):
|
|
|
|
if self._min_width is not None or self._min_height is not None:
|
|
|
|
super().minsize(self._apply_window_scaling(self._min_width), self._apply_window_scaling(self._min_height))
|
|
|
|
if self._max_width is not None or self._max_height is not None:
|
|
|
|
super().maxsize(self._apply_window_scaling(self._max_width), self._apply_window_scaling(self._max_height))
|
2022-05-12 23:55:28 +03:00
|
|
|
|
2022-08-16 19:14:30 +03:00
|
|
|
def withdraw(self):
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._window_exists is False:
|
|
|
|
self._withdraw_called_before_window_exists = True
|
2022-08-16 19:14:30 +03:00
|
|
|
super().withdraw()
|
|
|
|
|
|
|
|
def iconify(self):
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._window_exists is False:
|
|
|
|
self._iconify_called_before_window_exists = True
|
2022-08-16 19:14:30 +03:00
|
|
|
super().iconify()
|
|
|
|
|
2022-02-18 16:33:45 +03:00
|
|
|
def update(self):
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._window_exists is False:
|
2022-08-19 01:18:01 +03:00
|
|
|
if sys.platform.startswith("win"):
|
2022-10-02 04:23:10 +03:00
|
|
|
if not self._withdraw_called_before_window_exists and not self._iconify_called_before_window_exists:
|
2022-08-19 01:18:01 +03:00
|
|
|
# print("window dont exists -> deiconify in update")
|
|
|
|
self.deiconify()
|
2022-08-19 01:13:00 +03:00
|
|
|
|
2023-02-05 05:02:21 +03:00
|
|
|
self._window_exists = True
|
|
|
|
|
2022-02-18 16:33:45 +03:00
|
|
|
super().update()
|
|
|
|
|
|
|
|
def mainloop(self, *args, **kwargs):
|
2022-10-02 04:23:10 +03:00
|
|
|
if not self._window_exists:
|
2022-08-19 01:18:01 +03:00
|
|
|
if sys.platform.startswith("win"):
|
2023-02-05 05:02:21 +03:00
|
|
|
self._windows_set_titlebar_color(self._get_appearance_mode())
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if not self._withdraw_called_before_window_exists and not self._iconify_called_before_window_exists:
|
2022-08-19 01:18:01 +03:00
|
|
|
# print("window dont exists -> deiconify in mainloop")
|
|
|
|
self.deiconify()
|
2022-08-19 01:13:00 +03:00
|
|
|
|
2023-02-05 05:02:21 +03:00
|
|
|
self._window_exists = True
|
|
|
|
|
2022-02-18 16:33:45 +03:00
|
|
|
super().mainloop(*args, **kwargs)
|
|
|
|
|
2022-10-04 00:50:59 +03:00
|
|
|
def resizable(self, width: bool = None, height: bool = None):
|
2022-11-12 22:59:10 +03:00
|
|
|
current_resizable_values = super().resizable(width, height)
|
2022-10-04 00:50:59 +03:00
|
|
|
self._last_resizable_args = ([], {"width": width, "height": height})
|
2022-02-21 17:35:08 +03:00
|
|
|
|
|
|
|
if sys.platform.startswith("win"):
|
2022-11-01 02:37:30 +03:00
|
|
|
self._windows_set_titlebar_color(self._get_appearance_mode())
|
2022-02-21 17:35:08 +03:00
|
|
|
|
2022-11-12 22:59:10 +03:00
|
|
|
return current_resizable_values
|
|
|
|
|
2022-11-01 02:37:30 +03:00
|
|
|
def minsize(self, width: int = None, height: int = None):
|
2022-10-02 04:23:10 +03:00
|
|
|
self._min_width = width
|
|
|
|
self._min_height = height
|
|
|
|
if self._current_width < width:
|
|
|
|
self._current_width = width
|
|
|
|
if self._current_height < height:
|
|
|
|
self._current_height = height
|
|
|
|
super().minsize(self._apply_window_scaling(self._min_width), self._apply_window_scaling(self._min_height))
|
2022-05-12 23:55:28 +03:00
|
|
|
|
2022-11-01 02:37:30 +03:00
|
|
|
def maxsize(self, width: int = None, height: int = None):
|
2022-10-02 04:23:10 +03:00
|
|
|
self._max_width = width
|
|
|
|
self._max_height = height
|
|
|
|
if self._current_width > width:
|
|
|
|
self._current_width = width
|
|
|
|
if self._current_height > height:
|
|
|
|
self._current_height = height
|
|
|
|
super().maxsize(self._apply_window_scaling(self._max_width), self._apply_window_scaling(self._max_height))
|
2022-05-12 23:55:28 +03:00
|
|
|
|
2022-07-17 22:41:13 +03:00
|
|
|
def geometry(self, geometry_string: str = None):
|
|
|
|
if geometry_string is not None:
|
2022-10-02 04:23:10 +03:00
|
|
|
super().geometry(self._apply_geometry_scaling(geometry_string))
|
2022-07-17 22:41:13 +03:00
|
|
|
|
|
|
|
# update width and height attributes
|
2022-10-02 04:23:10 +03:00
|
|
|
width, height, x, y = self._parse_geometry_string(geometry_string)
|
2022-08-05 21:38:05 +03:00
|
|
|
if width is not None and height is not None:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._current_width = max(self._min_width, min(width, self._max_width)) # bound value between min and max
|
|
|
|
self._current_height = max(self._min_height, min(height, self._max_height))
|
2022-07-17 22:41:13 +03:00
|
|
|
else:
|
2022-10-13 18:28:33 +03:00
|
|
|
return self._reverse_geometry_scaling(super().geometry())
|
2022-05-02 00:29:14 +03:00
|
|
|
|
2022-10-16 21:13:19 +03:00
|
|
|
def configure(self, **kwargs):
|
|
|
|
if "fg_color" in kwargs:
|
2022-11-11 01:27:55 +03:00
|
|
|
self._fg_color = self._check_color_type(kwargs.pop("fg_color"))
|
2022-10-29 02:20:32 +03:00
|
|
|
super().configure(bg=self._apply_appearance_mode(self._fg_color))
|
2022-01-07 22:54:45 +03:00
|
|
|
|
|
|
|
for child in self.winfo_children():
|
2022-10-16 21:13:19 +03:00
|
|
|
try:
|
2022-10-02 04:23:10 +03:00
|
|
|
child.configure(bg_color=self._fg_color)
|
2022-10-16 21:13:19 +03:00
|
|
|
except Exception:
|
|
|
|
pass
|
2021-12-31 21:07:53 +03:00
|
|
|
|
2022-10-16 21:13:19 +03:00
|
|
|
super().configure(**pop_from_dict_by_set(kwargs, self._valid_tk_configure_arguments))
|
|
|
|
check_kwargs_empty(kwargs)
|
2021-12-31 21:07:53 +03:00
|
|
|
|
2022-10-03 01:33:06 +03:00
|
|
|
def cget(self, attribute_name: str) -> any:
|
|
|
|
if attribute_name == "fg_color":
|
|
|
|
return self._fg_color
|
|
|
|
else:
|
|
|
|
return super().cget(attribute_name)
|
|
|
|
|
2023-01-21 16:22:18 +03:00
|
|
|
def wm_iconbitmap(self, bitmap=None, default=None):
|
|
|
|
self._iconbitmap_method_called = True
|
|
|
|
super().wm_iconbitmap(bitmap, default)
|
|
|
|
|
2023-01-24 14:45:29 +03:00
|
|
|
def iconbitmap(self, bitmap=None, default=None):
|
|
|
|
self._iconbitmap_method_called = True
|
|
|
|
super().wm_iconbitmap(bitmap, default)
|
|
|
|
|
2023-01-21 16:22:18 +03:00
|
|
|
def _windows_set_titlebar_icon(self):
|
|
|
|
try:
|
|
|
|
# if not the user already called iconbitmap method, set icon
|
|
|
|
if not self._iconbitmap_method_called:
|
|
|
|
customtkinter_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
self.iconbitmap(os.path.join(customtkinter_directory, "assets", "icons", "CustomTkinter_icon_Windows.ico"))
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
2022-10-22 15:24:04 +03:00
|
|
|
@classmethod
|
|
|
|
def _enable_macos_dark_title_bar(cls):
|
|
|
|
if sys.platform == "darwin" and not cls._deactivate_macos_window_header_manipulation: # macOS
|
2021-12-31 21:07:53 +03:00
|
|
|
if Version(platform.python_version()) < Version("3.10"):
|
|
|
|
if Version(tkinter.Tcl().call("info", "patchlevel")) >= Version("8.6.9"): # Tcl/Tk >= 8.6.9
|
|
|
|
os.system("defaults write -g NSRequiresAquaSystemAppearance -bool No")
|
2022-05-02 00:29:14 +03:00
|
|
|
# This command allows dark-mode for all programs
|
2021-12-31 21:07:53 +03:00
|
|
|
|
2022-10-22 15:24:04 +03:00
|
|
|
@classmethod
|
|
|
|
def _disable_macos_dark_title_bar(cls):
|
|
|
|
if sys.platform == "darwin" and not cls._deactivate_macos_window_header_manipulation: # macOS
|
2021-12-31 21:07:53 +03:00
|
|
|
if Version(platform.python_version()) < Version("3.10"):
|
|
|
|
if Version(tkinter.Tcl().call("info", "patchlevel")) >= Version("8.6.9"): # Tcl/Tk >= 8.6.9
|
|
|
|
os.system("defaults delete -g NSRequiresAquaSystemAppearance")
|
|
|
|
# This command reverts the dark-mode setting for all programs.
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _windows_set_titlebar_color(self, color_mode: str):
|
2022-02-17 18:39:39 +03:00
|
|
|
"""
|
|
|
|
Set the titlebar color of the window to light or dark theme on Microsoft Windows.
|
|
|
|
|
|
|
|
Credits for this function:
|
|
|
|
https://stackoverflow.com/questions/23836000/can-i-change-the-title-bar-in-tkinter/70724666#70724666
|
|
|
|
|
|
|
|
MORE INFO:
|
|
|
|
https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
|
|
|
|
"""
|
|
|
|
|
2022-10-22 15:24:04 +03:00
|
|
|
if sys.platform.startswith("win") and not self._deactivate_windows_window_header_manipulation:
|
2022-02-18 16:33:45 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._window_exists:
|
|
|
|
self._state_before_windows_set_titlebar_color = self.state()
|
2022-08-19 01:13:00 +03:00
|
|
|
# print("window_exists -> state_before_windows_set_titlebar_color: ", self.state_before_windows_set_titlebar_color)
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._state_before_windows_set_titlebar_color != "iconic" or self._state_before_windows_set_titlebar_color != "withdrawn":
|
2023-02-05 05:02:21 +03:00
|
|
|
self.focused_widget_before_widthdraw = self.focus_get()
|
2022-08-19 01:13:00 +03:00
|
|
|
super().withdraw() # hide window so that it can be redrawn after the titlebar change so that the color change is visible
|
|
|
|
else:
|
|
|
|
# print("window dont exists -> withdraw and update")
|
2023-02-05 05:02:21 +03:00
|
|
|
self.focused_widget_before_widthdraw = self.focus_get()
|
2022-08-19 01:13:00 +03:00
|
|
|
super().withdraw()
|
2022-02-21 17:35:08 +03:00
|
|
|
super().update()
|
|
|
|
|
|
|
|
if color_mode.lower() == "dark":
|
|
|
|
value = 1
|
|
|
|
elif color_mode.lower() == "light":
|
|
|
|
value = 0
|
|
|
|
else:
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
hwnd = ctypes.windll.user32.GetParent(self.winfo_id())
|
|
|
|
DWMWA_USE_IMMERSIVE_DARK_MODE = 20
|
|
|
|
DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19
|
|
|
|
|
|
|
|
# try with DWMWA_USE_IMMERSIVE_DARK_MODE
|
|
|
|
if ctypes.windll.dwmapi.DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE,
|
|
|
|
ctypes.byref(ctypes.c_int(value)),
|
|
|
|
ctypes.sizeof(ctypes.c_int(value))) != 0:
|
|
|
|
|
|
|
|
# try with DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20h1
|
|
|
|
ctypes.windll.dwmapi.DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1,
|
|
|
|
ctypes.byref(ctypes.c_int(value)),
|
|
|
|
ctypes.sizeof(ctypes.c_int(value)))
|
|
|
|
|
|
|
|
except Exception as err:
|
|
|
|
print(err)
|
2022-02-17 18:39:39 +03:00
|
|
|
|
2023-02-05 05:02:21 +03:00
|
|
|
if self._window_exists or True:
|
2022-08-19 01:13:00 +03:00
|
|
|
# print("window_exists -> return to original state: ", self.state_before_windows_set_titlebar_color)
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._state_before_windows_set_titlebar_color == "normal":
|
2022-08-19 01:13:00 +03:00
|
|
|
self.deiconify()
|
2022-10-02 04:23:10 +03:00
|
|
|
elif self._state_before_windows_set_titlebar_color == "iconic":
|
2022-08-19 01:13:00 +03:00
|
|
|
self.iconify()
|
2022-10-02 04:23:10 +03:00
|
|
|
elif self._state_before_windows_set_titlebar_color == "zoomed":
|
2022-08-19 01:13:00 +03:00
|
|
|
self.state("zoomed")
|
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self.state(self._state_before_windows_set_titlebar_color) # other states
|
2022-08-19 01:13:00 +03:00
|
|
|
else:
|
|
|
|
pass # wait for update or mainloop to be called
|
2022-02-17 18:39:39 +03:00
|
|
|
|
2023-02-05 05:02:21 +03:00
|
|
|
if self.focused_widget_before_widthdraw is not None:
|
|
|
|
self.after(1, self.focused_widget_before_widthdraw.focus)
|
|
|
|
self.focused_widget_before_widthdraw = None
|
|
|
|
|
2022-11-01 02:37:30 +03:00
|
|
|
def _set_appearance_mode(self, mode_string: str):
|
|
|
|
super()._set_appearance_mode(mode_string)
|
2021-12-31 21:07:53 +03:00
|
|
|
|
2022-02-17 18:39:39 +03:00
|
|
|
if sys.platform.startswith("win"):
|
2022-11-01 02:37:30 +03:00
|
|
|
self._windows_set_titlebar_color(mode_string)
|
2022-02-17 18:39:39 +03:00
|
|
|
|
2022-10-29 02:20:32 +03:00
|
|
|
super().configure(bg=self._apply_appearance_mode(self._fg_color))
|