[Tkinter-discuss] tkinter: screenmmwidth

Michael Lange klappnase at web.de
Thu Nov 28 19:00:05 CET 2013


Hi,

On Wed, 27 Nov 2013 22:10:08 -0800
Josef Gabriel <josefg at gmail.com> wrote:

> I am not very familiar with the tkinter source code, please bear with
> me. I am using Windows7 Sp1 and python 2.7 on a laptop with no attached
> display. The screen specifications are 280 mm. The screen physically
> measures 275 mm. The screen EDID states 280 mm as well.
> winfo_screenmmwidth reports 361 mm.
> 
> 
> Where does tkinter extract the winfo_screenmmwidth information? I assume
> this is through the pywin32 api, but I don't know. I seem to have run
> into a dead end because I cannot view the _tkinter module. I assume the
> _tkinter module uses the pywin32 api, but I'm not sure where it's
> getting the information. I plan on using this data to calculate the
> pixels per centimeter (ppcm) for a gui I am writing.
> 
> I have written a function to extract the extended display identification
> data (EDID) information from the windows registry. Is there anything
> wroing with this method?
> 
> Thank you in advance.

the screenmmwidth value in fact does not have anything particular to do
with Python, but is instead the return value of the corresponding Tk
function (I'm not sure how this value is calculated by Tk though).
I can only guess, but if you get an incorrect value it might have
something to do with a dpi value that is not correctly recognised for
some reason (possibly because of bad edid data from your monitor, at
least that's what I had here).

You can check which dpi value Tk assumes with:

    dpi = root.winfo_fpixels('1i')
(or
    dpi = root.winfo_pixels('1i')
if you prefer an integer value).
If you replace '1i' with '1m' you should get a mm-value.
So with
    root.winfo_screenwidth() / root.winfo_fpixels('1m')
you should be able to calculate the screenmmwidth without having to rely
on the Tk routine (again, not sure if Tk doesn't do just the same ;).

One thing that might be intersting for you, you can even adjust the dpi
value your Tk window uses if you call:

    root.tk.call('tk', 'scaling', '-displayof', '.', desired_dpi/72.0)

_before_ creating any widgets. I have been using this in an app where I
let the users pick the value for desired_dpi from a spinbox so they can
take care that a distance that is supposed to be e.g. 10 cm actually has
the requested cm-size on the screen. 

I am not sure if taking values from the registry is a good idea, probably
it depends on what you want to achieve; to me it sounds a little as if a
way that works on your own system might fail on another, but in fact I
don't know much about registry values ;)

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Peace was the way.
		-- Kirk, "The City on the Edge of Forever", stardate
unknown


More information about the Tkinter-discuss mailing list