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

Skip to content

Commit 2ee25ac

Browse files
authored
Merge pull request #25501 from richardsheridan/tk_photoimage_resize
FIX: Tk photoimage resize
2 parents 22d7585 + c118579 commit 2ee25ac

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 5 additions & 5 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,9 @@ 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._tkphoto = tk.PhotoImage(
261-
master=self._tkcanvas, width=int(width), height=int(height))
262-
self._tkcanvas.create_image(
260+
self._tkcanvas.delete(self._tkcanvas_image_region)
261+
self._tkphoto.configure(width=int(width), height=int(height))
262+
self._tkcanvas_image_region = self._tkcanvas.create_image(
263263
int(width / 2), int(height / 2), image=self._tkphoto)
264264
ResizeEvent("resize_event", self)._process()
265265
self.draw_idle()

0 commit comments

Comments
 (0)