mirror of
https://github.com/python/cpython
synced 2024-09-05 16:38:56 +00:00
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.
|
||||
Return a :class:`Font` representation of a tk named font.
|
||||
|
||||
.. versionchanged:: 3.10
|
||||
The *root* parameter was added.
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
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 @@ def test_names(self):
|
|||
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 @@ def test_names(self):
|
|||
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 a new issue