def test_names(self): names = font.names(self.root) self.assertIsInstance(names, tuple) self.assertTrue(names) for name in names: self.assertIsInstance(name, (str, unicode)) self.assertTrue(name) self.assertIn(fontname, names)
def findfont(self, names): "Return name of first font family derived from names." for name in names: if name.lower() in (x.lower() for x in tkfont.names(root=self)): font = tkfont.Font(name=name, exists=True, root=self) return font.actual()['family'] elif name.lower() in (x.lower() for x in tkfont.families(root=self)): return name
def fix_scaling(root): """Scale fonts on HiDPI displays.""" import tkFont scaling = float(root.tk.call('tk', 'scaling')) if scaling > 1.4: for name in tkFont.names(root): font = tkFont.Font(root=root, name=name, exists=True) size = int(font['size']) if size < 0: font['size'] = int(round(-0.75*size))
def setfonts(): for fontname in tkFont.names(): default_font = tkFont.nametofont(fontname) default_font.configure(size=14)