0

I'm trying to see how recently an Event occurred (so that I can ignore the backlog of events that built up while a first event is being processed.) I see that events have a time attribute in milliseconds, but it doesn't line up with the system time I get from calling time.time(). Does anyone know how to convert between the two? Thanks!

Example

from Tkinter import Tk, Label
from time import time

def print_fn(event): print event.time, time()

app = Tk()
label = Label(app, text='Click Here!')
label.bind('<Button>', print_fn)
label.pack()
app.mainloop()

Output

1430467703 1360190553.41
a-ron
  • 1
  • 1

1 Answers1

1

The event.time attribute would be useful for determining the time between two Tkinter events.

event.time

This attribute is set to an integer which has no absolute meaning, but is incremented every millisecond. This allows your application to determine, for example, the length of time between two mouse clicks.

time.time

Return the time in seconds since the epoch as a floating point number. Note that even though the time is always returned as a floating point number, not all systems provide time with a better precision than 1 second. While this function normally returns non-decreasing values, it can return a lower value than a previous call if the system clock has been set back between the two calls.

To measure how much time has elapsed we generally use time.time or time.clock like this:

start = time.clock()
somefunction()
elapsed = time.clock() - start

You wouldn't have to use event.time at all.

More info about this can be found here: link

Community
  • 1
  • 1
Honest Abe
  • 8,430
  • 4
  • 49
  • 64
  • I'm actually not trying to see how long it takes to run a function; I'm trying to roughly estimate the lag between the event and the corresponding function call. The lag can be quite long if a previous event invoked a function that takes a long time to execute; the recent event will sit in the Tkinter queue until the function call finishes. I find it problematic to let lots of events pile up, since the user may not realize they're invoking the time-consuming function many times. – a-ron Feb 07 '13 at 18:42