How to disable the callback to control variable when hovering (not clicking) the mouse above the slider (not trough) of the tkinter Scale widget, after clicking on/dealing with other widget(s)?
Demo procedure:
1.) Run demo script below
2.) Click button '(Re-) Set DoubleVar to float value'
3.) Watch the (python) Shell for callback from tracing the control variable when hovering the FIRST time the mouse above the slider after setting the DoubleVar to float.
4.) Potentially repeat step 2.) and 3.)
import tkinter as tk
def func_set():
dvar.set(1.23456789)
def traceCallback(var, index, mode):
print('\nTraceback: ', var)
print('DoubleVar value: ', dvar.get())
# Demo script
root = tk.Tk()
root.title('Demo of hovering effect')
mainframe = tk.Frame(root)
mainframe.grid(sticky='NSWE', padx=50, pady=50)
# tk.DoubleVar
dvar = tk.DoubleVar()
dvar.set(2)
# Trace changes on DoubleVar
dvar.trace_add('write', traceCallback)
# Scale widget
scale = tk.Scale(mainframe, from_=0, to_=5, length=500, orient='horizontal', resolution=0.5, variable=dvar)
scale.grid(sticky='NSWE')
# Button widgets
button_set = tk.Button(mainframe, command=func_set, text='(Re-) Set DoubleVar to float value')
button_set.grid(column=0, row=1)
root.mainloop()
I'd like to bind the tkinter Scale widget to a tkinter DoubleVar (float) variable, but having a defined increment (e.g. 0.5) and displaying the rounded value accordingly on the widget.
Any suggestions?
I'm using Python 3.8+ on Windows 10.