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

Jeff Epler jepler at unpythonic.net
Fri Aug 20 14:07:12 CEST 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: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20040820/859782d5/attachment.pgp


More information about the Tkinter-discuss mailing list