8000 Switch Tk to using PNG files for buttons. · matplotlib/matplotlib@e6fb401 · GitHub
[go: up one dir, main page]

Skip to content

Commit e6fb401

Browse files
committed
Switch Tk to using PNG files for buttons.
In Tk 8.6, support was added for PNG files, so it can read those directly. In older versions, we can use Pillow's Tk support to do the same, since we hard-require it now.
1 parent b6c43c4 commit e6fb401

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def __init__(self, canvas, window, *, pack_toolbar=True):
502502
else:
503503
self._buttons[text] = button = self._Button(
504504
text,
505-
str(cbook._get_data_path(f"images/{image_file}.gif")),
505+
str(cbook._get_data_path(f"images/{image_file}.png")),
506506
toggle=callback in ["zoom", "pan"],
507507
command=getattr(self, callback),
508508
)
@@ -567,7 +567,11 @@ def set_cursor(self, cursor):
567567
pass
568568

569569
def _Button(self, text, image_file, toggle, command):
570-
image = (tk.PhotoImage(master=self, file=image_file)
570+
if tk.TkVersion >= 8.6:
571+
PhotoImage = tk.PhotoImage
572+
else:
573+
from PIL.ImageTk import PhotoImage
574+
image = (PhotoImage(master=self, file=image_file)
571575
if image_file is not None else None)
572576
if not toggle:
573577
b = tk.Button(master=self, text=text, image=image, command=command)
@@ -718,8 +722,6 @@ def set_cursor(self, cursor):
718722

719723

720724
class ToolbarTk(ToolContainerBase, tk.Frame):
721-
_icon_extension = '.gif'
722-
723725
def __init__(self, toolmanager, window):
724726
ToolContainerBase.__init__(self, toolmanager)
725727
xmin, xmax = self.toolmanager.canvas.figure.bbox.intervalx

0 commit comments

Comments
 (0)
0