Skip to content

Commit 40ea023

Browse files
FIX: avoid silently invalid tk.Canvas.delete
delete can only be applied to the integer identifiers returned by e.g. Canvas.create_image
1 parent 17fd9de commit 40ea023

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ def __init__(self, figure=None, master=None):
176176
width=w, height=h, borderwidth=0, highlightthickness=0)
177177
self._tkphoto = tk.PhotoImage(
178178
master=self._tkcanvas, width=w, height=h)
179-
self._tkcanvas.create_image(w//2, h//2, image=self._tkphoto)
179+
self._tkcanvas_image_region = self._tkcanvas.create_image(
180+
w//2, h//2, image=self._tkphoto)
180181
self._tkcanvas.bind("<Configure>", self.resize)
181182
if sys.platform == 'win32':
182183
self._tkcanvas.bind("<Map>", self._update_device_pixel_ratio)
@@ -256,10 +257,10 @@ def resize(self, event):
256257
hinch = height / dpival
257258
self.figure.set_size_inches(winch, hinch, forward=False)
258259

259-
self._tkcanvas.delete(self._tkphoto)
260+
self._tkcanvas.delete(self._tkcanvas_image_region)
260261
self._tkphoto = tk.PhotoImage(
261262
master=self._tkcanvas, width=int(width), height=int(height))
262-
self._tkcanvas.create_image(
263+
self._tkcanvas_image_region = self._tkcanvas.create_image(
263264
int(width / 2), int(height / 2), image=self._tkphoto)
264265
ResizeEvent("resize_event", self)._process()
265266
self.draw_idle()

0 commit comments

Comments
 (0)