CTkToplevel icon issue
Can't set icon for CTkTopLevel. @TomSchimansky
I described that problem and offered fix here #1124
After implementing that fix you can just set your icon using following method:
class YourClass(customtkinter.CTkToplevel):
def __init__(self, ...):
...
self.wm_iconbitmap(YOUR_ICON)
我描述了這個問題並在此處提供了修復#1124
實施該修復後,您可以使用以下方法設置圖標:
class YourClass(customtkinter.CTkToplevel): def __init__(self, ...): ... self.wm_iconbitmap(YOUR_ICON)
ummm I have this question too.
I use "iconbitmap" or "wm_iconbitmap" but they don't work. I tried many times.
Same problem only the first "iconbitmap" or "wm_iconbitmap" work.
As of now the solution to work around this issue is to reset the icon on windows systems after 200ms.
With OOP:
from customtkinter import CTk, CTkToplevel
from sys import platform
class SecondWindow(CTkToplevel):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.title('Window 2')
self.geometry("300x200")
self.iconbitmap(default="test_images/favicon.ico")
# Because CTkToplevel currently is bugged on windows
# and doesn't check if a user specified icon is set
# we need to set the icon again after 200ms
if platform.startswith("win"):
self.after(200, lambda: self.iconbitmap("test_images/favicon.ico"))
class App(CTk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.title('Window 1')
self.geometry("300x200")
self.iconbitmap(default="test_images/favicon.ico")
SecondWindow()
if __name__ == '__main__':
app = App()
app.mainloop()
Without OOP
from customtkinter import CTk, CTkToplevel
from sys import platform
app = CTk()
app.title('Window 1')
app.geometry("300x200")
app.iconbitmap(default="test_images/favicon.ico")
top = CTkToplevel()
top.title('Window 2')
top.geometry("300x200")
top.iconbitmap(default="test_images/favicon.ico")
# Because CTkToplevel currently is bugged on windows
# and doesn't check if a user specified icon is set
# we need to set the icon again after 200ms
if platform.startswith("win"):
top.after(200, lambda: top.iconbitmap("test_images/favicon.ico"))
if __name__ == '__main__':
app.mainloop()
This bug happens because CTkToplevel's __init__ doesn't look if a user specified icon is set before applying it's own:
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
Can't set icon for CTkTopLevel. @TomSchimansky
you can easily fix this by changing the default logo with your desired logo!!
@HACKwithSPIDY
you can easily fix this by changing the default logo with your desired logo!!
I know but it is not the proper solution. You should be able to change the toplevel icon without any issue, but somehow the icon changes to the default logo after using iconbitmap (within a second). Currently the better solution is to use the after method. This issue will be closed when it is fixed properly.