views:

358

answers:

1

Does anyone know if it is possible (and if yes, how) to bind an event (Python + Tkinter on MS Windows) to a system date change?

I know I can have .after events checking once in a while; I'm asking if I can somehow have an event fired whenever the system date/time changes, either automatically (e.g. for daylight saving time) or manually.

MS Windows sends such events to applications and Tkinter does receive them; I know, because if I have an .after timer waiting and I set the date/time after the timer's expiration, the timer event fires instantly.

+1  A: 

I know, because if I have an .after timer waiting and I set the date/time after the timer's expiration, the timer event fires instantly.

That could just mean that Tkinter (or Tk) is polling the system clock as part of the event loop to figure out when to run timers.

If you're using Windows, Mark Hammond's book notes that you can use the win32evtlogutil module to respond to changes in the Windows event log. Basically it works like this:

import win32evtlogutil
def onEvent(record):
  # Do something with the event log record
win32evtlogutil.FeedEventLogRecords(onEvent)

But you'll need to get docs on the structure of the event records (I don't feel like typing out the whole chapter, sorry :-) ). Also I don't know if date changes turn up in the event log anyway.

Really, though, is it so bad to just poll the system clock? It seems easiest and I don't think it would slow you down much.

(finally, a comment: I don't know about your country, but here in NZ, daylight savings doesn't involve a date change; only the time changes (from 2am-3am, or vice-versa))

John Fouhy
Here, too, only the time changes for DST / non-DST; I care for _any_ change to the system clock, be it time adjustment or date change. I'll check if I wasn't clear enough in my wording of the question. Thanks for your answer.
ΤΖΩΤΖΙΟΥ
And you are correct; Tkinter perhaps is just polling the clock every now and then.
ΤΖΩΤΖΙΟΥ