Repeat a function after displaying a message box every n seconds

advertisements

I want to set a function to repeat again again after the message box is shown. A short example of code is shown below that what i exactly want to do

def setInterval(func,time,args):
    e = threading.Event()
    while not e.wait(time):
        func(args)

def foo(data):
    print data
    aa("what")
def aa(a):
    print(a)

tkMessageBox.showinfo("Regret","nope")

setInterval(foo,5,"fsrty")

All things are okay but the problem is only that once the messgae box is shown its give "not responding error".Anyone please help to find out the solution


You will need to use the .after method since threading never work well this tkinter and nor does a while loop.

import Tkinter as tk
import TkMessageBox

def setInterval(func,time,args):
        func(args)
        root.after(time, setInterval(func, time, args))
root.tk.Tk()
root.withdraw()
def foo(data):
    print data
    aa("what")
def aa(a):
    print(a)

tkMessageBox.showinfo("Regret","nope")
setInterval(foo, 5, "fsrty")
root.mainloop()