8000 Fix scaling in Tk on non-Windows systems · matplotlib/matplotlib@f95e8ee · GitHub
[go: up one dir, main page]

Skip to content

Commit f95e8ee

Browse files
committed
Fix scaling in Tk on non-Windows systems
1 parent 0da7d89 commit f95e8ee

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ def __init__(self, figure=None, master=None):
176176
self._tkcanvas_image_region = self._tkcanvas.create_image(
177177
w//2, h//2, image=self._tkphoto)
178178
self._tkcanvas.bind("<Configure>", self.resize)
179-
if sys.platform == 'win32':
180-
self._tkcanvas.bind("<Map>", self._update_device_pixel_ratio)
179+
self._tkcanvas.bind("<Map>", self._update_device_pixel_ratio)
181180
self._tkcanvas.bind("<Key>", self.key_press)
182181
self._tkcanvas.bind("<Motion>", self.motion_notify_event)
183182
self._tkcanvas.bind("<Enter>", self.enter_notify_event)
@@ -234,11 +233,15 @@ def filter_destroy(event):
234233
self._rubberband_rect_white = None
235234

236235
def _update_device_pixel_ratio(self, event=None):
237-
# Tk gives scaling with respect to 72 DPI, but Windows screens are
238-
# scaled vs 96 dpi, and pixel ratio settings are given in whole
239-
# percentages, so round to 2 digits.
240-
ratio = round(self._tkcanvas.tk.call('tk', 'scaling') / (96 / 72), 2)
241-
if self._set_device_pixel_ratio(ratio):
236+
ratio = None
237+
if sys.platform == 'win32':
238+
# Tk gives scaling with respect to 72 DPI, but Windows screens are
239+
# scaled vs 96 dpi, and pixel ratio settings are given in whole
240+
# percentages, so round to 2 digits.
241+
ratio = round(self._tkcanvas.tk.call('tk', 'scaling') / (96 / 72), 2)
242+
elif sys.platform == "linux":
243+
ratio = self._tkcanvas.winfo_fpixels('1i') / 96
244+
if ratio is not None and self._set_device_pixel_ratio(ratio):
242245
# The easiest way to resize the canvas is to resize the canvas
243246
# widget itself, since we implement all the logic for resizing the
244247
# canvas backing store on that event.

0 commit comments

Comments
 (0)
0