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

Skip to content

Commit 132d713

Browse files
authored
Merge pull request #22153 from meeseeksmachine/auto-backport-of-pr-22147-on-v3.5.x
Backport PR #22147 on branch v3.5.x (Fix loading user-defined icons for Tk toolbar)
2 parents 23be033 + 313a785 commit 132d713

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,15 @@ def _set_image_for_button(self, button):
636636
if button._image_file is None:
637637
return
638638

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

0 commit comments

Comments
 (0)