“displayof” in tkinter.font.Font.measure

2019-08-12 09:23发布

问题:

The following measure method is defined in class Font of module /usr/lib/python3.5/tkinter/font or import tkinter.font:

def measure(self, text, displayof=None):
    "Return text width"
    args = (text,)
    if displayof:
        args = ('-displayof', displayof, text)
    return self._tk.getint(self._call("font", "measure", self.name, *args))

Questions:

  1. What isdisplayof?
  2. When and how do I use displayof?

回答1:

It takes a widget as an argument. While rare, it’s possible to have multiple windows displaying on multiple displays with different pixel densities. If you have such a setup, this lets you decide which widget/display to use as the basis for determining the size of the string.

The default for this parameter is the root window.