summaryrefslogtreecommitdiffstats
path: root/Lib/tkinter
diff options
context:
space:
mode:
authorE-Paine <63801254+E-Paine@users.noreply.github.com>2021-06-23 10:30:24 (GMT)
committerGitHub <noreply@github.com>2021-06-23 10:30:24 (GMT)
commite9c8f784fa13ea3a51df3b72a498a3896ec9e768 (patch)
treeedf7923fdb889b0a66c136b3387a3b4ba132950d /Lib/tkinter
parent5c7940257e1f611e7284fd504887bd29a63d0a94 (diff)
downloadcpython-e9c8f784fa13ea3a51df3b72a498a3896ec9e768.zip
cpython-e9c8f784fa13ea3a51df3b72a498a3896ec9e768.tar.gz
cpython-e9c8f784fa13ea3a51df3b72a498a3896ec9e768.tar.bz2
bpo-44404: tkinter `after` support callable classes (GH-26812)
Diffstat (limited to 'Lib/tkinter')
-rw-r--r--Lib/tkinter/__init__.py6
-rw-r--r--Lib/tkinter/test/test_tkinter/test_misc.py7
2 files changed, 12 insertions, 1 deletions
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
index 369004c..2513c97 100644
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -841,7 +841,11 @@ class Misc:
self.deletecommand(name)
except TclError:
pass
- callit.__name__ = func.__name__
+ try:
+ callit.__name__ = func.__name__
+ except AttributeError:
+ # Required for callable classes (bpo-44404)
+ callit.__name__ = type(func).__name__
name = self._register(callit)
return self.tk.call('after', ms, name)
diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py
index d4b7cbd..ab8f647 100644
--- a/Lib/tkinter/test/test_tkinter/test_misc.py
+++ b/Lib/tkinter/test/test_tkinter/test_misc.py
@@ -1,3 +1,4 @@
+import functools
import unittest
import tkinter
import enum
@@ -98,6 +99,12 @@ class MiscTest(AbstractTkTest, unittest.TestCase):
with self.assertRaises(tkinter.TclError):
root.tk.call(script)
+ # Call with a callable class
+ count = 0
+ timer1 = root.after(0, functools.partial(callback, 42, 11))
+ root.update() # Process all pending events.
+ self.assertEqual(count, 53)
+
def test_after_idle(self):
root = self.root