From 8a537076cebc4adeb7003e8287f2fa8698392413 Mon Sep 17 00:00:00 2001 From: TomSchimansky Date: Sat, 7 Jan 2023 01:16:15 +0100 Subject: [PATCH 1/2] added icon on Windows for CTkToplevel, fixed #960 --- customtkinter/windows/ctk_tk.py | 2 +- customtkinter/windows/ctk_toplevel.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/customtkinter/windows/ctk_tk.py b/customtkinter/windows/ctk_tk.py index 4770ed0..61e5609 100644 --- a/customtkinter/windows/ctk_tk.py +++ b/customtkinter/windows/ctk_tk.py @@ -44,7 +44,7 @@ class CTk(tkinter.Tk, CTkAppearanceModeBaseClass, CTkScalingBaseClass): # Set Windows titlebar icon if sys.platform.startswith("win"): 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")) + self.after(200, lambda: self.iconbitmap(os.path.join(customtkinter_directory, "assets", "icons", "CustomTkinter_icon_Windows.ico"))) except Exception: pass diff --git a/customtkinter/windows/ctk_toplevel.py b/customtkinter/windows/ctk_toplevel.py index 4e43839..a409a03 100644 --- a/customtkinter/windows/ctk_toplevel.py +++ b/customtkinter/windows/ctk_toplevel.py @@ -38,6 +38,14 @@ class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseCl CTkScalingBaseClass.__init__(self, scaling_type="window") check_kwargs_empty(kwargs, raise_error=True) + try: + # Set Windows titlebar icon + if sys.platform.startswith("win"): + customtkinter_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + self.after(200, lambda: self.iconbitmap(os.path.join(customtkinter_directory, "assets", "icons", "CustomTkinter_icon_Windows.ico"))) + except Exception: + pass + self._current_width = 200 # initial window size, always without scaling self._current_height = 200 self._min_width: int = 0 From a79502dc0320aac5fd71a56495f1fe453bd0bf26 Mon Sep 17 00:00:00 2001 From: TomSchimansky Date: Sat, 7 Jan 2023 01:21:28 +0100 Subject: [PATCH 2/2] replaced sys.stderr with warnings.warn #932 --- .../windows/widgets/core_widget_classes/ctk_base_class.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py b/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py index 8b389f3..a75ab01 100644 --- a/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py +++ b/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py @@ -1,4 +1,5 @@ import sys +import warnings import tkinter import tkinter.ttk as ttk from typing import Union, Callable, Tuple @@ -158,7 +159,7 @@ class CTkBaseClass(tkinter.Frame, CTkAppearanceModeBaseClass, CTkScalingBaseClas return font elif type(font) == tuple and len(font) == 1: - sys.stderr.write(f"{type(self).__name__} Warning: font {font} given without size, will be extended with default text size of current theme\n") + warnings.warn(f"{type(self).__name__} Warning: font {font} given without size, will be extended with default text size of current theme\n") return font[0], ThemeManager.theme["text"]["size"] elif type(font) == tuple and 2 <= len(font) <= 6: @@ -178,8 +179,8 @@ class CTkBaseClass(tkinter.Frame, CTkAppearanceModeBaseClass, CTkScalingBaseClas elif isinstance(image, CTkImage): return image else: - sys.stderr.write(f"{type(self).__name__} Warning: Given image is not CTkImage but {type(image)}. " + - f"Image can not be scaled on HighDPI displays, use CTkImage instead.\n") + warnings.warn(f"{type(self).__name__} Warning: Given image is not CTkImage but {type(image)}. " + + f"Image can not be scaled on HighDPI displays, use CTkImage instead.\n") return image def _update_dimensions_event(self, event):