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?