Created
June 18, 2019 02:06
-
-
Save cppio/2d9555af9c5ad63469937e8dc6306b18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from tkinter import ttk | |
| class DebouncedEntry(ttk.Entry): | |
| def __init__(self, master, delay, callback, validate=None): | |
| super().__init__(master, validate="key") | |
| self["validatecommand"] = self.register(self.validate), "%P" | |
| self.delay = delay | |
| self.callback = callback | |
| self.validate = validate | |
| self.alarm_id = None | |
| def validate(self, entry): | |
| if entry and self.validate and not self.validate(entry): | |
| return False | |
| if self.alarm_id is not None: | |
| self.after_cancel(self.alarm_id) | |
| self.alarm_id = None | |
| if entry: | |
| self.alarm_id = self.after(self.delay, self.callback, entry) | |
| return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment