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

Skip to content

Commit 9073fed

Browse files
daniilSQuLogic
andcommitted
Fix loading user-defined icons for Tk toolbar
Co-Authored-By: Elliott Sales de Andrade <[email protected]>
1 parent 80d4e23 commit 9073fed

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
@@ -643,9 +643,15 @@ def _set_image_for_button(self, button):
643643
if button._image_file is None:
644644
return
645645

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

0 commit comments

Comments
 (0)