Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8366ea4

Browse files
authored
Merge pull request #22145 from daniilS/tk_iconphoto
Make Tk windows use the same icon as other backends
2 parents d624571 + f10c557 commit 8366ea4

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -907,14 +907,21 @@ def new_figure_manager_given_figure(cls, num, figure):
907907
window.withdraw()
908908

909909
# Put a Matplotlib icon on the window rather than the default tk
910-
# icon. Tkinter doesn't allow colour icons on linux systems, but
911-
# tk>=8.5 has a iconphoto command which we call directly. See
912-
# https://mail.python.org/pipermail/tkinter-discuss/2006-November/000954.html
910+
# icon. See https://www.tcl.tk/man/tcl/TkCmd/wm.html#M50
911+
#
912+
# `ImageTk` can be replaced with `tk` whenever the minimum
913+
# supported Tk version is increased to 8.6, as Tk 8.6+ natively
914+
# supports PNG images.
913915
icon_fname = str(cbook._get_data_path(
914-
'images/matplotlib_128.ppm'))
915-
icon_img = tk.PhotoImage(file=icon_fname, master=window)
916+
'images/matplotlib.png'))
917+
icon_img = ImageTk.PhotoImage(file=icon_fname, master=window)
918+
919+
icon_fname_large = str(cbook._get_data_path(
920+
'images/matplotlib_large.png'))
921+
icon_img_large = ImageTk.PhotoImage(
922+
file=icon_fname_large, master=window)
916923
try:
917-
window.iconphoto(False, icon_img)
924+
window.iconphoto(False, icon_img_large, icon_img)
918925
except Exception as exc:
919926
# log the failure (due e.g. to Tk version), but carry on
920927
_log.info('Could not load matplotlib icon: %s', exc)

0 commit comments

Comments
 (0)