Skip to content

Backport PR #22147 on branch v3.5.x (Fix loading user-defined icons for Tk toolbar) #22153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
10 changes: 8 additions & 2 deletions lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,15 @@ def _set_image_for_button(self, button):
if button._image_file is None:
return

# Allow _image_file to be relative to Matplotlib's "images" data
# directory.
path_regular = cbook._get_data_path('images', button._image_file)
path_large = path_regular.with_name(
path_regular.name.replace('.png', '_large.png'))
size = button.winfo_pixels('18p')
with Image.open(button._image_file.replace('.png', '_large.png')
if size > 24 else button._image_file) as im:
# Use the high-resolution (48x48 px) icon if it exists and is needed
with Image.open(path_large if (size > 24 and path_large.exists())
else path_regular) as im:
image = ImageTk.PhotoImage(im.resize((size, size)), master=self)
button.configure(image=image, height='18p', width='18p')
button._ntimage = image # Prevent garbage collection.
Expand Down