This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Python 3 tkinter measurement problem
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: Ackbach, serhiy.storchaka, terry.reedy
Priority: normal Keywords:

Created on 2018-10-07 05:09 by Ackbach, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg327265 - (view) Author: Adrian Keister (Ackbach) Date: 2018-10-07 05:09
tkinter.Tk().winfo_screenmmwidth() and tkinter.Tk().winfo_screenmmheight() give manifestly incorrect values in Windows. This does not appear to be an issue in Linux. I have not tested a Mac. The values reported in Windows are too large by as much as 58%. Searching online seems to indicate that the issue is some applications in Windows are "dpi aware"; unfortunately, none of the so-called work-arounds I've found actually fix the problem. The tkinter.Tk().winfo_screenwidth() and tkinter.Tk().winfo_screenheight() functions, reporting their results in pixels, appear to be correct. A MWE is simply

import tkinter
tkinter.Tk().winfo_screenmmwidth()

This reports a 508 mm on my 15.6" screen, when the true value is closer to 343 mm. This is a 48% error, and hence an unusable result. 

Thank you for your time!
msg327598 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-10-12 16:52
I cannot reproduce 'too large'.  My screen in 340 mm high.  It is reported as 305 in console Python 3.7.1rc1 and in IDLE run normally and with -n (no subprocess) and in console Python 3.6.7.  The point of trying '-n' is to run the test code in the IDLE process, which now makes a DPIAwareness call.  I am fairly sure that my console does not. 

In any case, tkinter interfaces to tcl/tk via _tkinter.  Unless it can be shown that _tkinter distorts the value returned by tk, I think this should be closed as '3rd party'.
msg327599 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-12 17:05
This is a Tk issue. Tkinter returns the same result as a plain Tk (unsurprisingly).

$ rlwrap wish
% winfo screenmmwidth .
1016
% winfo screenwidth .
3840
% puts [expr "25.4*[winfo screenwidth .]/[winfo screenmmwidth .]"]
96.0
History
Date User Action Args
2022-04-11 14:59:06adminsetgithub: 79099
2018-10-12 17:05:24serhiy.storchakasetstatus: open -> closed
resolution: third party
messages: + msg327599

stage: resolved
2018-10-12 16:52:07terry.reedysetnosy: + terry.reedy, serhiy.storchaka

messages: + msg327598
versions: + Python 3.7, Python 3.8
2018-10-07 05:09:01Ackbachcreate