문제

이벤트 (MS Wind

나는 한 번에 한 번 확인한 후에 가끔 확인할 수 있다는 것을 알고있다. 시스템 날짜/시간이 자동으로 (예 : 일광 절약 시간) 또는 수동으로 변경 될 때마다 이벤트가 발사 될 수 있는지 묻습니다.

MS Windows는 그러한 이벤트를 응용 프로그램으로 보냅니다. Tkinter는이 행사를받습니다. 타이머가 대기하고 타이머 만료 후 날짜/시간을 설정하면 타이머 이벤트가 즉시 발생하기 때문에 알고 있습니다.

도움이 되었습니까?

해결책

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))

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top