Re: Please help -- Tkinter Scale widget with DoubleVar is actingweird

Discussion in 'Python' started by Fredrik Lundh, Aug 19, 2004.

  1. Jared Cohen wrote:

    > Hi all. I'm currently using a Tkinter Scale widget which uses a
    > DoubleVar as its control variable. I then use the "trace_variable('w',
    > callback)" method to invoke a callback whenever the DoubleVar changes.
    >
    > The problem is this: the callback is triggered when the slider moves (as
    > it should), but it's also triggered when I just HOVER the mouse over the
    > slider without clicking! Somehow or other, it must think that the
    > control variable is being changed, even though it isn't. I *think* that
    > this problem is related to the loss of precision that DoubleVars can
    > have, but I'm not really sure. Has anyone else experienced this problem?
    > How can I fix this?


    you could use a "command" callback instead of a traced variable:

    import sys, Tkinter, types

    root = Tkinter.Tk()

    def callback(value):
    print float(value)

    slider = Tkinter.Scale(root,
    from_ = 0.0,
    to = 1.0,
    resolution = 0.1,
    command = callback,
    orient = 'horizontal')
    slider.grid(sticky='ew')

    root.mainloop()

    (use slider.get() to get the current value from outside the callback,
    and slider.set(x) to set it).

    </F>
    Fredrik Lundh, Aug 19, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Fouhy
    Replies:
    2
    Views:
    597
    John Fouhy
    Jun 25, 2004
  2. Jeff Epler
    Replies:
    0
    Views:
    497
    Jeff Epler
    Aug 20, 2004
  3. Jeff Epler
    Replies:
    0
    Views:
    444
    Jeff Epler
    Aug 23, 2004
  4. Replies:
    0
    Views:
    284
  5. Frederic Rentsch
    Replies:
    0
    Views:
    224
    Frederic Rentsch
    Jul 8, 2012
Loading...

Share This Page