From f95e8ee8c3b7958fd327928cdf533563ca3c02f9 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Thu, 18 Jul 2024 00:58:21 +0200 Subject: [PATCH] Fix scaling in Tk on non-Windows systems --- lib/matplotlib/backends/_backend_tk.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/backends/_backend_tk.py b/lib/matplotlib/backends/_backend_tk.py index df06440a9826..d7c2f59be6b9 100644 --- a/lib/matplotlib/backends/_backend_tk.py +++ b/lib/matplotlib/backends/_backend_tk.py @@ -176,8 +176,7 @@ def __init__(self, figure=None, master=None): self._tkcanvas_image_region = self._tkcanvas.create_image( w//2, h//2, image=self._tkphoto) self._tkcanvas.bind("", self.resize) - if sys.platform == 'win32': - self._tkcanvas.bind("", self._update_device_pixel_ratio) + self._tkcanvas.bind("", self._update_device_pixel_ratio) self._tkcanvas.bind("", self.key_press) self._tkcanvas.bind("", self.motion_notify_event) self._tkcanvas.bind("", self.enter_notify_event) @@ -234,11 +233,15 @@ def filter_destroy(event): self._rubberband_rect_white = None def _update_device_pixel_ratio(self, event=None): - # Tk gives scaling with respect to 72 DPI, but Windows screens are - # scaled vs 96 dpi, and pixel ratio settings are given in whole - # percentages, so round to 2 digits. - ratio = round(self._tkcanvas.tk.call('tk', 'scaling') / (96 / 72), 2) - if self._set_device_pixel_ratio(ratio): + ratio = None + if sys.platform == 'win32': + # Tk gives scaling with respect to 72 DPI, but Windows screens are + # scaled vs 96 dpi, and pixel ratio settings are given in whole + # percentages, so round to 2 digits. + ratio = round(self._tkcanvas.tk.call('tk', 'scaling') / (96 / 72), 2) + elif sys.platform == "linux": + ratio = self._tkcanvas.winfo_fpixels('1i') / 96 + if ratio is not None and self._set_device_pixel_ratio(ratio): # The easiest way to resize the canvas is to resize the canvas # widget itself, since we implement all the logic for resizing the # canvas backing store on that event. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy