Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue with iconbitmap in CTkToplevel #2095

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions customtkinter/windows/ctk_toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ def __init__(self, *args,
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
# fix iconbitmap
# 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
Expand All @@ -63,7 +64,7 @@ def __init__(self, *args,
super().title("CTkToplevel")

# indicator variables
self._iconbitmap_method_called = True
self._iconbitmap_method_called = False # indicates if iconbitmap method was called by user
self._state_before_windows_set_titlebar_color = None
self._windows_set_titlebar_color_called = False # indicates if windows_set_titlebar_color was called, stays True until revert_withdraw_after_windows_set_titlebar_color is called
self._withdraw_called_after_windows_set_titlebar_color = False # indicates if withdraw() was called after windows_set_titlebar_color
Expand Down Expand Up @@ -202,6 +203,11 @@ def cget(self, attribute_name: str) -> any:
def wm_iconbitmap(self, bitmap=None, default=None):
self._iconbitmap_method_called = True
super().wm_iconbitmap(bitmap, default)

# This function did not exist before
def iconbitmap(self, bitmap=None, default=None):
self._iconbitmap_method_called = True
super().wm_iconbitmap(bitmap, default)

def _windows_set_titlebar_icon(self):
try:
Expand Down