Oct-01-2021, 05:40 AM
Something like this?
import tkinter as tk from itertools import cycle class MainFrame(tk.Frame): def __init__(self, *args, **kwargs): super().__init__(*args, *kwargs) self._timer = False self._button1_state = cycle(("disabled", "normal")) self._create() self._layout() self._binds() def _create(self): self.button1 = tk.Button(self, text="Button1") def _layout(self): self.button1.pack(padx=5, pady=5) def _binds(self): self.button1.bind("<ButtonRelease-1>", self._on_button1) def _on_button1(self, event): if not self._timer: self.toggle_button1() else: self.after_cancel(self._timer) self.button1.config(state="normal") self._timer = None def toggle_button1(self): self.button1.config(state=next(self._button1_state)) self._timer = self.after(100, self.toggle_button1) def main(): app = tk.Tk() mainframe = MainFrame(app) mainframe.pack() app.mainloop() if __name__ == "__main__": main()