Reputation: 3469
Is it possible to make the Scale Widget return to the center of the scale when it is not in use?
Currently, if I click and drag the scale widget to one side, it will remain in that position when I unclick the slider. Is it possible to make the slider return to the center when it is unclicked / no longer being dragged?
Current code to work on:
w = Scale(master, from_=0, to=1, orient=HORIZONTAL, command=some_function)
w.pack()
Upvotes: 2
Views: 257
Reputation: 386230
The simplest solution would be to bind to the event <ButtonRelease-
>, which will trigger when you release the mouse button. You can then call the set
method to set the value to whatever you want.
For example:
self.scale = tk.Scale(...)
self.scale.bind("<ButtonRelease-1>", self.reset_scale)
...
def reset_scale(self, event):
self.scale.set(0)
Upvotes: 2