2

I'm writing a tkinter app where I'd like the widgets to be a specific size in inches on the display. I have a 24-inch Samsung display plugged into a Mac Mini. The display is roughly 520 mm wide and 295 mm high. When I tried specifying the dimensions of canvas widgets in inches, everything was too small by about a third.

Here's what I've tried:

from tkinter import *
root = Tk()
root.winfo_screenmmheight()
381
root.winfo_screenmmwidth()
677
root.winfo_screenheight()
1080
root.winfo_screenwidth()
1920
1080/381
2.8346456692913384
1920/677
2.8360413589364843
_*25.4    # 25.4 millimeters per inch 
72.0354505169867
root.tk.call('tk', 'scaling', 1.33)
''
root.winfo_screenmmheight()
286
root.winfo_screenmmwidth()
509

If I do root.tk.call('tk', 'scaling', 1.33) in my program, then things are the size I want (or close enough.)

It seems clear that the problem is that tkinter is assuming that my display has 72 pixels per inch whereas it really has 96 pixels per inch. I can scale my display to get what I want, but this will look wrong if someone with a 72 PPI display runs the code. I've looked at a number of posts on SO related to this, and root.tk.call was the only thing I found that helped at all, but it's not portable.

Is there a platform-independent way to find out how many PPI the display has? Or do I have to settle for making the app take up a fixed portion of the screen?

saulspatz
  • 5,011
  • 5
  • 36
  • 47
  • Why aren't you using relative sizes instead of absolute ones since this would make your GUI independent of screen size or resolution? – albert Dec 12 '15 at 19:49
  • Yes, I understand that, as I indicated in my question. However, in this instance I would like a fixed size, if I can achieve it. – saulspatz Dec 12 '15 at 19:54
  • tkinter is at the mercy of what the os reports. I think your only solution is to require the user to do a quick setup step to set the scaling. – Bryan Oakley Dec 13 '15 at 02:46
  • @BryanOakley Thanks, that's what I was afraid of. – saulspatz Dec 13 '15 at 05:59

0 Answers0