bpo-41851: tkinter font add neg and equal methods by E-Paine · Pull Request #22396 · python/cpython · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Doc/library/tkinter.font.rst
5 changes: 5 additions & 0 deletions Lib/tkinter/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ def config(self, **options):

configure = config

def equal(self, other):
if not isinstance(other, Font):
raise TypeError("Value for comparison must also be a Font")
return self.actual() == other.actual()

def measure(self, text, displayof=None):
"Return text width"
args = (text,)
Expand Down
12 changes: 12 additions & 0 deletions Lib/tkinter/test/test_tkinter/test_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ def test_eq(self):
self.assertNotEqual(font1, 0)
self.assertEqual(font1, ALWAYS_EQ)

def test_equal(self):
font1 = font.Font(root=self.root, size=32)
font2 = font1.copy()
self.assertTrue(font1.equal(font2))
self.assertTrue(font2.equal(font1))
font2['size'] = 30
self.assertFalse(font1.equal(font2))
font3 = font.Font(root=self.root, size=30, underline=True)
self.assertFalse(font2.equal(font3))
font2['underline'] = True
self.assertTrue(font2.equal(font3))

def test_measure(self):
self.assertIsInstance(self.font.measure('abc'), int)

Expand Down