Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
tkinter.font.Font Class Reference

List of all members.

Public Member Functions

def __init__
def __str__
def __eq__
def __getitem__
def __setitem__
def __del__
def copy
def actual
def cget
def config
def measure
def metrics

Public Attributes

 name
 delete_font

Static Public Attributes

 configure = config

Private Member Functions

def _set
def _get
def _mkdict

Private Attributes

 _root
 _split
 _call

Detailed Description

Represents a named font.

Constructor options are:

font -- font specifier (name, system font, or (family, size, style)-tuple)
name -- name to use for this font configuration (defaults to a unique name)
exists -- does a named font by this name already exist?
   Creates a new named font if False, points to the existing font if True.
   Raises _tkinter.TclError if the assertion is false.

   the following are ignored if font is specified:

family -- font 'family', e.g. Courier, Times, Helvetica
size -- font size in points
weight -- font thickness: NORMAL, BOLD
slant -- font slant: ROMAN, ITALIC
underline -- font underlining: false (0), true (1)
overstrike -- font strikeout: false (0), true (1)

Definition at line 24 of file font.py.


Constructor & Destructor Documentation

def tkinter.font.Font.__init__ (   self,
  root = None,
  font = None,
  name = None,
  exists = False,
  options 
)

Definition at line 66 of file font.py.

00066 
00067     def __init__(self, root=None, font=None, name=None, exists=False, **options):
00068         if not root:
00069             root = tkinter._default_root
00070         if font:
00071             # get actual settings corresponding to the given font
00072             font = root.tk.splitlist(root.tk.call("font", "actual", font))
00073         else:
00074             font = self._set(options)
00075         if not name:
00076             name = "font" + str(id(self))
00077         self.name = name
00078 
00079         if exists:
00080             self.delete_font = False
00081             # confirm font exists
00082             if self.name not in root.tk.call("font", "names"):
00083                 raise tkinter._tkinter.TclError(
00084                     "named font %s does not already exist" % (self.name,))
00085             # if font config info supplied, apply it
00086             if font:
00087                 root.tk.call("font", "configure", self.name, *font)
00088         else:
00089             # create new font (raises TclError if the font exists)
00090             root.tk.call("font", "create", self.name, *font)
00091             self.delete_font = True
00092         # backlinks!
00093         self._root  = root
00094         self._split = root.tk.splitlist
00095         self._call  = root.tk.call

Here is the call graph for this function:

Here is the caller graph for this function:

def tkinter.font.Font.__del__ (   self)

Definition at line 108 of file font.py.

00108 
00109     def __del__(self):
00110         try:
00111             if self.delete_font:
00112                 self._call("font", "delete", self.name)
00113         except (KeyboardInterrupt, SystemExit):
00114             raise
00115         except Exception:
00116             pass


Member Function Documentation

def tkinter.font.Font.__eq__ (   self,
  other 
)

Definition at line 99 of file font.py.

00099 
00100     def __eq__(self, other):
00101         return isinstance(other, Font) and self.name == other.name

def tkinter.font.Font.__getitem__ (   self,
  key 
)

Definition at line 102 of file font.py.

00102 
00103     def __getitem__(self, key):
00104         return self.cget(key)

Here is the call graph for this function:

def tkinter.font.Font.__setitem__ (   self,
  key,
  value 
)

Definition at line 105 of file font.py.

00105 
00106     def __setitem__(self, key, value):
00107         self.configure(**{key: value})

def tkinter.font.Font.__str__ (   self)

Definition at line 96 of file font.py.

00096 
00097     def __str__(self):
00098         return self.name

def tkinter.font.Font._get (   self,
  args 
) [private]

Definition at line 54 of file font.py.

00054 
00055     def _get(self, args):
00056         options = []
00057         for k in args:
00058             options.append("-"+k)
00059         return tuple(options)

Here is the caller graph for this function:

def tkinter.font.Font._mkdict (   self,
  args 
) [private]

Definition at line 60 of file font.py.

00060 
00061     def _mkdict(self, args):
00062         options = {}
00063         for i in range(0, len(args), 2):
00064             options[args[i][1:]] = args[i+1]
00065         return options

Here is the caller graph for this function:

def tkinter.font.Font._set (   self,
  kw 
) [private]

Definition at line 47 of file font.py.

00047 
00048     def _set(self, kw):
00049         options = []
00050         for k, v in kw.items():
00051             options.append("-"+k)
00052             options.append(str(v))
00053         return tuple(options)

Here is the caller graph for this function:

def tkinter.font.Font.actual (   self,
  option = None 
)

Definition at line 121 of file font.py.

00121 
00122     def actual(self, option=None):
00123         "Return actual font attributes"
00124         if option:
00125             return self._call("font", "actual", self.name, "-"+option)
00126         else:
00127             return self._mkdict(
00128                 self._split(self._call("font", "actual", self.name))
00129                 )

Here is the call graph for this function:

Here is the caller graph for this function:

def tkinter.font.Font.cget (   self,
  option 
)

Definition at line 130 of file font.py.

00130 
00131     def cget(self, option):
00132         "Get font attribute"
00133         return self._call("font", "config", self.name, "-"+option)

Here is the caller graph for this function:

def tkinter.font.Font.config (   self,
  options 
)

Definition at line 134 of file font.py.

00134 
00135     def config(self, **options):
00136         "Modify font attributes"
00137         if options:
00138             self._call("font", "config", self.name,
00139                   *self._set(options))
00140         else:
00141             return self._mkdict(
00142                 self._split(self._call("font", "config", self.name))
00143                 )

Here is the call graph for this function:

def tkinter.font.Font.copy (   self)

Definition at line 117 of file font.py.

00117 
00118     def copy(self):
00119         "Return a distinct copy of the current font"
00120         return Font(self._root, **self.actual())

Here is the call graph for this function:

def tkinter.font.Font.measure (   self,
  text 
)

Definition at line 146 of file font.py.

00146 
00147     def measure(self, text):
00148         "Return text width"
00149         return int(self._call("font", "measure", self.name, text))

def tkinter.font.Font.metrics (   self,
  options 
)
Return font metrics.

For best performance, create a dummy widget
using this font before calling this method.

Definition at line 150 of file font.py.

00150 
00151     def metrics(self, *options):
00152         """Return font metrics.
00153 
00154         For best performance, create a dummy widget
00155         using this font before calling this method."""
00156 
00157         if options:
00158             return int(
00159                 self._call("font", "metrics", self.name, self._get(options))
00160                 )
00161         else:
00162             res = self._split(self._call("font", "metrics", self.name))
00163             options = {}
00164             for i in range(0, len(res), 2):
00165                 options[res[i][1:]] = int(res[i+1])
00166             return options

Here is the call graph for this function:


Member Data Documentation

Definition at line 94 of file font.py.

Definition at line 92 of file font.py.

Definition at line 93 of file font.py.

Definition at line 144 of file font.py.

Definition at line 79 of file font.py.

Definition at line 76 of file font.py.


The documentation for this class was generated from the following file: