CTkInputDialog & CTkToplevel icon
Hello,
I am quite new to Python and this nice library. I use CTkMessagebox library to have some specific messagebox, even though it doesn't really follow the 'design' of my GUI. I needed Input Dialog and added it and saw that it doesn't take the icon of my GUI ? Not sure if it's an issue, I checked on the documentation and couldn't find anything related to a specific argument to paste the icon. I guess it is the same for CTkToplevel widget ?
The red icon is my main GUI icon, while the blue one, is the one automatically set up.
Thank you in advance, Regards Solchael
Designing your own input dialog with a Toplevel window provides greater control and the opportunity to tailor it to your needs. For reference, you might explore an example I developed for personal use, which you can find here: https://github.com/JanPanthera/_GuiFramework/blob/dev_JanPanthera/GuiFramework/widgets/custom_popup_message_box.py
def _on_delete_dictionary_file(self):
"""Delete the selected dictionary file."""
def callback_handler(is_confirmed):
if is_confirmed:
file_path = os.path.join(
self.dev_path,
self.get_var("dictionaries_path"),
self.scroll_list_dictionaries.get_checked_entries()[0],
)
file_ops.delete_file(file_path)
self.scroll_list_dictionaries.remove_checked_entries()
checked_entries = self.scroll_list_dictionaries.get_checked_entries()
if checked_entries:
self._create_popup_message_box(
self.loc("confirm_delete_dic_title"),
self.loc("confirm_delete_dic_msg"),
callback_handler,
)
# Helper Methods
def _create_PopupMessageBox(self, title, message, on_callback):
"""Create a popup message box with yes/no buttons."""
buttons = [
{"text": self.loc("yes"), "callback": lambda: on_callback(True)},
{"text": self.loc("no"), "callback": lambda: on_callback(False)},
]
return CustomPopupMessageBox(self, title=title, message=message, buttons=buttons)
@JanPanthera thank you sir.
I did play with both, top-level and input dialog from this library. And in both case the icon at the top left is always the blue one, while my main gui is the red one. Is there an attribute I am missing to change that blue icon? Or I can seek where is stored that blue icon and replace it?
import customtkinter
def main():
window = customtkinter.CTk()
window.title("Test Application")
window.geometry("800x600")
window.iconbitmap("TestApplication/ad_icon.ico")
popup = customtkinter.CTkToplevel(window)
popup.title("Popup")
popup.geometry("400x300")
window.after(1000, lambda: popup.iconbitmap("TestApplication/ad_icon.ico"))
window.mainloop()
if __name__ == "__main__":
main()
the issue is that the CTkToplevel does sets a default icon after 200ms, so you are setting the icon first, then thi gets triggered and overides your icon, just add a higher delay to your set call ;-)
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
@JanPanthera thank you again. I am not at home so I'll test it later !
Why does it behave like this? Why changing the icon alone? Is it to be able to have a little thing that says it's made with CustomTkinter? As I don't mind keeping the icon if it's the case. I would also remove the one I have on the main GUi and keep the one I add for the taskbar after creating the .exe.
I think its more a tkinter thing, since customtkinter is just a wrapper around the tkinter widgets. AND tkinter is old, really old 😹 So no wonder why some things just, WHY the heck xD
@JanPanthera thank you very much !
window.after(1000, lambda: popup.iconbitmap("TestApplication/ad_icon.ico"))
This work very good, I just changed the time to 200!
I think this can be closed as I don't think they'll do something about it ? I might check this weekend if I can find where is stored that icon, and maybe replace it directly in the library. It has to be set somewhere 😄
pip show customtkinter will show you where ctk is installed, and os.path.join(customtkinter_directory, "assets", "icons", "CustomTkinter_icon_Windows.ico") and there it is saved then xD
Ahaha thanks a lot ! I have to remember that for any future project !
You can also check here: customtkinter_directory\windows\ here you can check the code for each and adapt it per your needs.