bpo-35728: Add root parameter to tkinter.font.nametofont() (GH-23885)
This commit is contained in:
parent
675c97eb6c
commit
36a779e64c
|
@ -91,6 +91,9 @@ The different font weights and slants are:
|
|||
|
||||
Return the names of defined fonts.
|
||||
|
||||
.. function:: nametofont(name)
|
||||
.. function:: nametofont(name, root=None)
|
||||
|
||||
Return a :class:`Font` representation of a tk named font.
|
||||
|
||||
.. versionchanged:: 3.10
|
||||
The *root* parameter was added.
|
||||
|
|
|
@ -17,10 +17,10 @@ BOLD = "bold"
|
|||
ITALIC = "italic"
|
||||
|
||||
|
||||
def nametofont(name):
|
||||
def nametofont(name, root=None):
|
||||
"""Given the name of a tk named font, returns a Font representation.
|
||||
"""
|
||||
return Font(name=name, exists=True)
|
||||
return Font(name=name, exists=True, root=root)
|
||||
|
||||
|
||||
class Font:
|
||||
|
|
|
@ -101,6 +101,11 @@ class FontTest(AbstractTkTest, unittest.TestCase):
|
|||
self.assertTrue(name)
|
||||
self.assertIn(fontname, names)
|
||||
|
||||
def test_nametofont(self):
|
||||
testfont = font.nametofont(fontname, root=self.root)
|
||||
self.assertIsInstance(testfont, font.Font)
|
||||
self.assertEqual(testfont.name, fontname)
|
||||
|
||||
def test_repr(self):
|
||||
self.assertEqual(
|
||||
repr(self.font), f'<tkinter.font.Font object {fontname!r}>'
|
||||
|
@ -136,6 +141,16 @@ class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase):
|
|||
tkinter.NoDefaultRoot()
|
||||
self.assertRaises(RuntimeError, font.names)
|
||||
|
||||
def test_nametofont(self):
|
||||
self.assertRaises(RuntimeError, font.nametofont, fontname)
|
||||
root = tkinter.Tk()
|
||||
testfont = font.nametofont(fontname)
|
||||
self.assertIsInstance(testfont, font.Font)
|
||||
self.assertEqual(testfont.name, fontname)
|
||||
root.destroy()
|
||||
tkinter.NoDefaultRoot()
|
||||
self.assertRaises(RuntimeError, font.nametofont, fontname)
|
||||
|
||||
|
||||
tests_gui = (FontTest, DefaultRootTest)
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Added a root parameter to :func:`tkinter.font.nametofont`.
|
Loading…
Reference in New Issue