[Tkinter-discuss] Please help -- Tkinter Scale widget with DoubleVar is acting weird

Jeff Epler jepler at unpythonic.net
Fri Aug 20 08:07:12 EDT 2004


I do *not* see this behavior on
    fedora-release-2-4 (Fedora Core 2 Linux)
    python-2.3.3-6
    tcl-8.4.5-7
    tk-8.4.5-6

However, while dragging I can see a set to the same value multiple
times.  I suppose this happens when the mouse movement is too small to
move one "resolution" unit.

You could use a class which acts as a function wrapper to eliminate the
redundant calls to "callback":
    class RedundancyEliminator:
        def __init__(self, var, callback):
            self.var = var
            self.callback = callback
            self.lastval = var.get()

        def __call__(self, *args):
            newval = var.get()
            if newval != self.lastval:
                self.lastval = newval
                return self.callback(*args)
            return None

    def callback(*args):
       print var.get()

    var.trace_variable("w", RedundancyEliminator(var, callback))

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20040820/859782d5/attachment.sig>


More information about the Python-list mailing list