19 Aug 2004 17:32
Please help -- Tkinter Scale widget with DoubleVar is acting weird
Jared Cohen <Jared.Cohen <at> noaa.gov>
2004-08-19 15:32:56 GMT
2004-08-19 15:32:56 GMT
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?
As an aid, here's a quick stub program that illustrates the problem. Try (for example) moving the slider to 0.3, release the mouse button, then move the mouse pointer back and forth over the slider WITHOUT clicking. Each time the pointer passes over the slider, it will print the value.
import sys, Tkinter, types
root = Tkinter.Tk()
var = Tkinter.DoubleVar()
def callback(*args):
print var.get()
var.trace_variable("w", callback)
slider = Tkinter.Scale(root,
from_ = 0.0,
to = 1.0,
resolution = 0.1,
variable = var,
orient = 'horizontal')
slider.grid(sticky='ew')
root.mainloop()
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?
As an aid, here's a quick stub program that illustrates the problem. Try (for example) moving the slider to 0.3, release the mouse button, then move the mouse pointer back and forth over the slider WITHOUT clicking. Each time the pointer passes over the slider, it will print the value.
import sys, Tkinter, types
root = Tkinter.Tk()
var = Tkinter.DoubleVar()
def callback(*args):
print var.get()
var.trace_variable("w", callback)
slider = Tkinter.Scale(root,
from_ = 0.0,
to = 1.0,
resolution = 0.1,
variable = var,
orient = 'horizontal')
slider.grid(sticky='ew')
root.mainloop()
-- -- http://mail.python.org/mailman/listinfo/python-list
RSS Feed