Skip to content

Commit e9c8f78

Browse files
authored
bpo-44404: tkinter after support callable classes (GH-26812)
1 parent 5c79402 commit e9c8f78

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Lib/tkinter/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,11 @@ def callit():
841841
self.deletecommand(name)
842842
except TclError:
843843
pass
844-
callit.__name__ = func.__name__
844+
try:
845+
callit.__name__ = func.__name__
846+
except AttributeError:
847+
# Required for callable classes (bpo-44404)
848+
callit.__name__ = type(func).__name__
845849
name = self._register(callit)
846850
return self.tk.call('after', ms, name)
847851

Lib/tkinter/test/test_tkinter/test_misc.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import functools
12
import unittest
23
import tkinter
34
import enum
@@ -98,6 +99,12 @@ def callback(start=0, step=1):
9899
with self.assertRaises(tkinter.TclError):
99100
root.tk.call(script)
100101

102+
# Call with a callable class
103+
count = 0
104+
timer1 = root.after(0, functools.partial(callback, 42, 11))
105+
root.update() # Process all pending events.
106+
self.assertEqual(count, 53)
107+
101108
def test_after_idle(self):
102109
root = self.root
103110

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:mod:`tkinter`'s ``after()`` method now supports callables without the ``__name__`` attribute.

0 commit comments

Comments
 (0)