1010
1111import tkinter
1212
13+
1314# weight/slant
1415NORMAL = "normal"
1516ROMAN = "roman"
1617BOLD = "bold"
1718ITALIC = "italic"
1819
20+
1921def nametofont (name ):
2022 """Given the name of a tk named font, returns a Font representation.
2123 """
2224 return Font (name = name , exists = True )
2325
24- class Font :
2526
27+ class Font :
2628 """Represents a named font.
2729
2830 Constructor options are:
@@ -63,7 +65,8 @@ def _mkdict(self, args):
6365 options [args [i ][1 :]] = args [i + 1 ]
6466 return options
6567
66- def __init__ (self , root = None , font = None , name = None , exists = False , ** options ):
68+ def __init__ (self , root = None , font = None , name = None , exists = False ,
69+ ** options ):
6770 if not root :
6871 root = tkinter ._default_root
6972 if font :
@@ -138,8 +141,7 @@ def config(self, **options):
138141 * self ._set (options ))
139142 else :
140143 return self ._mkdict (
141- self ._split (self ._call ("font" , "config" , self .name ))
142- )
144+ self ._split (self ._call ("font" , "config" , self .name )))
143145
144146 configure = config
145147
@@ -155,27 +157,29 @@ def metrics(self, *options):
155157
156158 if options :
157159 return int (
158- self ._call ("font" , "metrics" , self .name , self ._get (options ))
159- )
160+ self ._call ("font" , "metrics" , self .name , self ._get (options )))
160161 else :
161162 res = self ._split (self ._call ("font" , "metrics" , self .name ))
162163 options = {}
163164 for i in range (0 , len (res ), 2 ):
164165 options [res [i ][1 :]] = int (res [i + 1 ])
165166 return options
166167
168+
167169def families (root = None ):
168170 "Get font families (as a tuple)"
169171 if not root :
170172 root = tkinter ._default_root
171173 return root .tk .splitlist (root .tk .call ("font" , "families" ))
172174
175+
173176def names (root = None ):
174177 "Get names of defined fonts (as a tuple)"
175178 if not root :
176179 root = tkinter ._default_root
177180 return root .tk .splitlist (root .tk .call ("font" , "names" ))
178181
182+
179183# --------------------------------------------------------------------
180184# test stuff
181185
0 commit comments