@@ -176,8 +176,7 @@ def __init__(self, figure=None, master=None):
176
176
self ._tkcanvas_image_region = self ._tkcanvas .create_image (
177
177
w // 2 , h // 2 , image = self ._tkphoto )
178
178
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 )
181
180
self ._tkcanvas .bind ("<Key>" , self .key_press )
182
181
self ._tkcanvas .bind ("<Motion>" , self .motion_notify_event )
183
182
self ._tkcanvas .bind ("<Enter>" , self .enter_notify_event )
@@ -234,11 +233,15 @@ def filter_destroy(event):
234
233
self ._rubberband_rect_white = None
235
234
236
235
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 ):
242
245
# The easiest way to resize the canvas is to resize the canvas
243
246
# widget itself, since we implement all the logic for resizing the
244
247
# canvas backing store on that event.
0 commit comments