Home | History | Annotate | Download | only in lib-tk

Lines Matching defs:Font

1 # Tkinter font wrapper
20 """Given the name of a tk named font, returns a Font representation.
22 return Font(name=name, exists=True)
24 class Font:
26 """Represents a named font.
30 font -- font specifier (name, system font, or (family, size, style)-tuple)
31 name -- name to use for this font configuration (defaults to a unique name)
32 exists -- does a named font by this name already exist?
33 Creates a new named font if False, points to the existing font if True.
36 the following are ignored if font is specified:
38 family -- font 'family', e.g. Courier, Times, Helvetica
39 size -- font size in points
40 weight -- font thickness: NORMAL, BOLD
41 slant -- font slant: ROMAN, ITALIC
42 underline -- font underlining: false (0), true (1)
43 overstrike -- font strikeout: false (0), true (1)
66 def __init__(self, root=None, font=None, name=None, exists=False, **options):
69 if font:
70 # get actual settings corresponding to the given font
71 font = root.tk.splitlist(root.tk.call("font", "actual", font))
73 font = self._set(options)
75 name = "font" + str(id(self))
80 # confirm font exists
81 if self.name not in root.tk.call("font", "names"):
82 raise Tkinter._tkinter.TclError, "named font %s does not already exist" % (self.name,)
83 # if font config info supplied, apply it
84 if font:
85 root.tk.call("font", "configure", self.name, *font)
87 # create new font (raises TclError if the font exists)
88 root.tk.call("font", "create", self.name, *font)
99 return self.name == other.name and isinstance(other, Font)
110 self._call("font", "delete", self.name)
117 "Return a distinct copy of the current font"
118 return Font(self._root, **self.actual())
121 "Return actual font attributes"
123 return self._call("font", "actual", self.name, "-"+option)
126 self._split(self._call("font", "actual", self.name))
130 "Get font attribute"
131 return self._call("font", "config", self.name, "-"+option)
134 "Modify font attributes"
136 self._call("font", "config", self.name,
140 self._split(self._call("font", "config", self.name))
147 return int(self._call("font", "measure", self.name, text))
150 """Return font metrics.
153 using this font before calling this method."""
157 self._call("font", "metrics", self.name, self._get(options))
160 res = self._split(self._call("font", "metrics", self.name))
167 "Get font families (as a tuple)"
170 return root.tk.splitlist(root.tk.call("font", "families"))
176 return root.tk.splitlist(root.tk.call("font", "names"))
185 # create a font
186 f = Font(family="times", size=30, weight=NORMAL)
202 f = Font(font=("Courier", 20, "bold"))
205 w = Tkinter.Label(root, text="Hello, world", font=f)
211 fb = Font(font=w["font"]).copy()
214 w.config(font=fb)