I have a GUI which contains a scale and a button widgets. When the button is clicked, it calls a function to delete the scale widget. I'd like this to happen only if the scale value has changed, that is, I want people to move the scale cursor before the button command could be activated. The default value on the scale is 0, and people are allowed to move the cursor and then come back on the 0. I've tried many things but couldn't figure out how to do it in a simple way.
Thank you in advance!
Here's a simplified version of my code :
from tkinter import *
def action(widget):
widget.destroy()
window = Tk()
value = DoubleVar()
scale = Scale(window, variable=value, resolution=1)
button = Button(window, command = lambda: action(scale))
scale.pack()
button.pack()
window.mainloop()
Here's a new version using the .trace method, as suggested by @Sun Bear . It still doesn't work, the "action" function doesn't seem to get the updated state variable.
from tkinter import *
def scalestate(*arg):
scale_activate = True
print("scale_activate is", scale_activate)
def action(widget):
if scale_activate:
widget.destroy()
window = Tk()
scale_activate = False
print("scale_activate is initially", scale_activate)
value = DoubleVar()
value.trace('w', scalestate)
scale = Scale(window, variable=value, orient=HORIZONTAL)
button = Button(window, command = lambda: action(scale))
scale.pack()
button.pack()
window.mainloop()