At the moment, this function is only used by the get_filename or folder with the no_window option set. Changes the icon that is shown on the title bar and on the task bar. NOTE - The file type is IMPORTANT and depends on the OS! Can pass in: * filename which must be a .ICO icon
(root, icon=None, pngbase64=None)
| 17951 | |
| 17952 | |
| 17953 | def _set_icon_for_tkinter_window(root, icon=None, pngbase64=None): |
| 17954 | """ |
| 17955 | At the moment, this function is only used by the get_filename or folder with the no_window option set. |
| 17956 | Changes the icon that is shown on the title bar and on the task bar. |
| 17957 | NOTE - The file type is IMPORTANT and depends on the OS! |
| 17958 | Can pass in: |
| 17959 | * filename which must be a .ICO icon file for windows, PNG file for Linux |
| 17960 | * bytes object |
| 17961 | * BASE64 encoded file held in a variable |
| 17962 | |
| 17963 | :param root: The window being modified |
| 17964 | :type root: (tk.Tk or tk.TopLevel) |
| 17965 | :param icon: Filename or bytes object |
| 17966 | :type icon: (str | bytes) |
| 17967 | :param pngbase64: Base64 encoded image |
| 17968 | :type pngbase64: (bytes) |
| 17969 | """ |
| 17970 | |
| 17971 | if type(icon) is bytes or pngbase64 is not None: |
| 17972 | wicon = tkinter.PhotoImage(data=icon if icon is not None else pngbase64) |
| 17973 | try: |
| 17974 | root.tk.call('wm', 'iconphoto', root._w, wicon) |
| 17975 | except: |
| 17976 | wicon = tkinter.PhotoImage(data=DEFAULT_BASE64_ICON) |
| 17977 | try: |
| 17978 | root.tk.call('wm', 'iconphoto', root._w, wicon) |
| 17979 | except Exception as e: |
| 17980 | print('Set icon exception', e) |
| 17981 | pass |
| 17982 | return |
| 17983 | |
| 17984 | wicon = icon |
| 17985 | try: |
| 17986 | root.iconbitmap(icon) |
| 17987 | except Exception as e: |
| 17988 | try: |
| 17989 | wicon = tkinter.PhotoImage(file=icon) |
| 17990 | root.tk.call('wm', 'iconphoto', root._w, wicon) |
| 17991 | except Exception as e: |
| 17992 | try: |
| 17993 | wicon = tkinter.PhotoImage(data=DEFAULT_BASE64_ICON) |
| 17994 | try: |
| 17995 | root.tk.call('wm', 'iconphoto', root._w, wicon) |
| 17996 | except Exception as e: |
| 17997 | print('Set icon exception', e) |
| 17998 | pass |
| 17999 | except: |
| 18000 | print('Set icon exception', e) |
| 18001 | pass |
| 18002 | |
| 18003 | |
| 18004 | # ==============================_GetNumLinesNeeded ==# |