Skip to content
Merged
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
38 changes: 21 additions & 17 deletions lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,23 +546,6 @@ def create_with_canvas(cls, canvas_class, figure, num):
window = tk.Tk(className="matplotlib")
window.withdraw()

# Put a Matplotlib icon on the window rather than the default tk
# icon. See https://www.tcl.tk/man/tcl/TkCmd/wm.html#M50
#
# `ImageTk` can be replaced with `tk` whenever the minimum
# supported Tk version is increased to 8.6, as Tk 8.6+ natively
# supports PNG images.
icon_fname = str(cbook._get_data_path(
'images/matplotlib_small.png'))
icon_img = ImageTk.PhotoImage(file=icon_fname, master=window)

icon_fname_large = str(cbook._get_data_path(
'images/matplotlib.png'))
icon_img_large = ImageTk.PhotoImage(
file=icon_fname_large, master=window)

window.iconphoto(False, icon_img_large, icon_img)

canvas = canvas_class(figure, master=window)
manager = cls(canvas, num, window)
if mpl.is_interactive():
Expand Down Expand Up @@ -612,6 +595,27 @@ def destroy(*args):
Gcf.destroy(self)
self.window.protocol("WM_DELETE_WINDOW", destroy)
self.window.deiconify()

# Put a Matplotlib icon on the window rather than the default tk
# icon. See https://www.tcl.tk/man/tcl/TkCmd/wm.html#M50
#
# The icon is set after calling deiconify() to avoid a bug when
# running IPython on Windows.
#
# `ImageTk` can be replaced with `tk` whenever the minimum
# supported Tk version is increased to 8.6, as Tk 8.6+ natively
# supports PNG images.
Comment thread
iccir marked this conversation as resolved.
Resolved
icon_fname = str(cbook._get_data_path(
'images/matplotlib_small.png'))
icon_img = ImageTk.PhotoImage(file=icon_fname, master=self.window)

icon_fname_large = str(cbook._get_data_path(
'images/matplotlib.png'))
icon_img_large = ImageTk.PhotoImage(
file=icon_fname_large, master=self.window)

self.window.iconphoto(False, icon_img_large, icon_img)

self.canvas._tkcanvas.focus_set()
else:
self.canvas.draw_idle()
Expand Down
Loading