1

I realize this is a trivial question, but I'm confused nonetheless.

I have a 13 inch MacBook Pro with retina display. My system claims a 2560-by-1600 resolution in System Report. I assumed that the Canvas command in tkinter measured height and width in pixels, and the tk documentation seem to indicate this too. Yet the following code, where I use 1200 as the width and 700 as the the height of a tkinter canvas, produces a canvas that mostly fills my screen.

What units are the canvas height and width in?

from tkinter import *

master = Tk()

x = 1200
y = 700

w = Canvas(master, width=x, height=y)
w.pack()


mainloop()
Potato
  • 551
  • 6
  • 15
  • it must be something with 'dots per pixel' setting, where a retina display uses 2 dots (what you measure as 2560x1600) for 1 pixel (defined by the program). Wikipedia [says](https://en.wikipedia.org/wiki/Retina_Display): _When an Apple product has a Retina Display, each user interface widget is doubled in width and height to compensate for the smaller pixels. Apple calls this mode HiDPI mode_ – Ciprian Tomoiagă Jan 24 '17 at 00:54
  • @CiprianTomoiaga Ah, that makes total sense. Thanks. I didn't know about that. – Potato Jan 24 '17 at 00:56

1 Answers1

5

You are correct, TkInter does measure size in pixels. BUT:

Retina Display has a higher density of hardware pixels to make the display look sharper. However, note that these do not correspond 1-to-1 to rendering pixels, which the programs use. From Wikipedia:

When an Apple product has a Retina Display, each user interface widget is doubled in width and height to compensate for the smaller pixels. Apple calls this mode HiDPI mode

This is also the case with any display which packs a high pixel density (DPI). So if you want your widgets to be at a certain percentage of the screen width/height, you should first detect if you're on a HiDPI display and scale your widget accordingly. This question may help.

Community
  • 1
  • 1
Ciprian Tomoiagă
  • 3,773
  • 4
  • 41
  • 65