Alberto Troiano wrote:
Thanks Kent but now I need you to explain me the code :(

That code won't work for you. It is for timing how long it takes to do something, not for generating repeated events.



To give you a graphic example how can make this function to run every 5 seconds


def foo():

print "Hello world!"

Here is a Tkinter program that updates the text of a label every second. It uses the root.after() method to schedule a callback. Since it is a one-time callback, the callback reschedules itself each time it is called.


This is not a great example of code structure but it is simple and demonstrates 
the concept.

from Tkinter import *

count = 0

def update():
    ''' Callback method updates the label '''
    global count
    count += 1
    label.configure(text=str(count))

    # Schedule another callback
    root.after(1000, update)


root=Tk() label=Label(root,text="0") label.pack()

b=Button(root,text="Bye",command='exit')
b.pack()

# Schedule the initial callback
root.after(1000, update)

root.mainloop()


Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to