Call function once after given time. MS specifies the time in milliseconds. FUNC gives the function which shall be called. Additional parameters are given as parameters to the function call. Return identifier to cancel scheduling with after_cancel.
(self, ms, func=None, *args, **kw)
| 864 | return self._nametowidget(name) |
| 865 | |
| 866 | def after(self, ms, func=None, *args, **kw): |
| 867 | """Call function once after given time. |
| 868 | |
| 869 | MS specifies the time in milliseconds. FUNC gives the |
| 870 | function which shall be called. Additional parameters |
| 871 | are given as parameters to the function call. Return |
| 872 | identifier to cancel scheduling with after_cancel.""" |
| 873 | if func is None: |
| 874 | # I'd rather use time.sleep(ms*0.001) |
| 875 | self.tk.call('after', ms) |
| 876 | return None |
| 877 | else: |
| 878 | def callit(): |
| 879 | try: |
| 880 | func(*args, **kw) |
| 881 | finally: |
| 882 | try: |
| 883 | self.deletecommand(name) |
| 884 | except TclError: |
| 885 | pass |
| 886 | try: |
| 887 | callit.__name__ = func.__name__ |
| 888 | except AttributeError: |
| 889 | # Required for callable classes (bpo-44404) |
| 890 | callit.__name__ = type(func).__name__ |
| 891 | name = self._register(callit) |
| 892 | return self.tk.call('after', ms, name) |
| 893 | |
| 894 | def after_idle(self, func, *args, **kw): |
| 895 | """Call FUNC once if the Tcl main loop has no event to |