Reputation: 25093
Using X on Linux, Tkinter (Python 3.12) tells me that I have a DPI value of ~96 (wrong), while the X server tells me that my DPI value is ~185 (correct).
In [1]: import tkinter as tk
...: root = tk.Tk()
...: print(root.winfo_fpixels('1i'))
...: root.destroy()
...:
...: xrandr_out = ! xrandr
...: xy_in = [int(mm[:-2])/25.4 for mm in xrandr_out[1][-13:].split(' x ')]
...: xy_pix = [int(pixels) for pixels in xrandr_out[2].split()[0].split('x')]
...: dpi_x, dpi_y = [pixels/dimension for pixels, dimension in zip(xy_pix, xy_in)]
...: print(dpi_x, dpi_y)
...:
96.08406304728547
185.35135135135135 185.66497461928932
In [2]:
(I'm sorry for the convoluted way of finding the real DPI value, it is possible that you have to adjust my code to make it work on your distribution.)
Where does Tkinter find the incorrect information regarding the DPI value?
Upvotes: 2
Views: 71