How can I call a delayed function in python?

I have a slider and I want to call a specific function only when the interaction is complete. The idea is to call the function after 500 ms (and not earlier). If the slider continues to move, the call is canceled. In other words, if the slider โ€œrestsโ€ for more than 500 ms, than the function calls.

thank

Update

    #slider

    def updateValue(self):
        #self._job = None
        #self.preview.updateContourValue(float(self.slider.get() ))
        print "updated value"

    timer = Timer(5.0, updateValue)

    def sliderCallback(self):
        timer.cancel()
        timer.start()
+5
source share
1 answer

Patrick: See this topic - How to create a timer using tkinter?

You can use Threading.Timer for this. It has a method cancelthat you can use to cancel it before it starts.

+2
source

All Articles