def test_after(self):
root = self.root
- def callback(start=0, step=1):
+ def callback(start=0, step=1, *, end=0):
nonlocal count
- count = start + step
+ count = start + step + end
# Without function, sleeps for ms.
self.assertIsNone(root.after(1))
root.update() # Process all pending events.
self.assertEqual(count, 53)
+ # Set up with callback with keyword args.
+ count = 0
+ timer1 = root.after(0, callback, 42, step=11, end=1)
+ root.update() # Process all pending events.
+ self.assertEqual(count, 54)
+
def test_after_idle(self):
root = self.root
- def callback(start=0, step=1):
+ def callback(start=0, step=1, *, end=0):
nonlocal count
- count = start + step
+ count = start + step + end
# Set up with callback with no args.
count = 0
with self.assertRaises(tkinter.TclError):
root.tk.call(script)
+ # Set up with callback with keyword args.
+ count = 0
+ idle1 = root.after_idle(callback, 42, step=11, end=1)
+ root.update() # Process all pending events.
+ self.assertEqual(count, 54)
+
def test_after_cancel(self):
root = self.root
if not name: return None
return self._nametowidget(name)
- def after(self, ms, func=None, *args):
+ def after(self, ms, func=None, *args, **kw):
"""Call function once after given time.
MS specifies the time in milliseconds. FUNC gives the
else:
def callit():
try:
- func(*args)
+ func(*args, **kw)
finally:
try:
self.deletecommand(name)
name = self._register(callit)
return self.tk.call('after', ms, name)
- def after_idle(self, func, *args):
+ def after_idle(self, func, *args, **kw):
"""Call FUNC once if the Tcl main loop has no event to
process.
Return an identifier to cancel the scheduling with
after_cancel."""
- return self.after('idle', func, *args)
+ return self.after('idle', func, *args, **kw)
def after_cancel(self, id):
"""Cancel scheduling of function identified with ID.