Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I call a function with delay in python?

Tags:

python

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

Thanks

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()
like image 647
aneuryzm Avatar asked Nov 06 '22 07:11

aneuryzm


1 Answers

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

You can use Threading.Timer to do this. It has a cancel method that you can use to cancel it before it runs.

like image 160
aaronasterling Avatar answered Nov 09 '22 03:11

aaronasterling