Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
a tkinter (ttk) button extension that repeatedly invokes the command whilst the button is held down, includes a simple exponential acceleration
from Tkinter import *
from ttk import *
class RepeatButton(Button):
def __init__(self, _, **kw):
Button.__init__(self, _)
self.config(**kw)
self.bind('<Button-1>', self._start)
self.bind('<ButtonRelease-1>', self._end)
def _start(self, event):
self._delay = 1500
self._on = True
self._do()
def _do(self):
if self._on:
self.invoke()
if self._delay > 100:
self._delay /= 2
self.after(self._delay, self._do)
def _end(self, event):
self._on = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.