Yes, it does. That timer does a callback in a different thread, and you
can't reliably touch a window from a thread that didn't create the window.
Just use a wx.Timer instead, as in the attached.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.
Your confusion is understandable. It's especially true because we
advise people to use Python-native components to solve problem whenever
they duplicate the facilities in wx, and that would seem to be the case
here.
The threading module's timer does spin off a separate thread, which
simply waits for a time and then calls the function. This short-lived
thread is thus guaranteed NOT to be the creator of any existing windows.
wx.Timer ends up calling the SetTimer API in Windows (or an equivalent
in other systems). When the interval expires, SetTimer fires off a
message to the window that owns the timer. (Actually, timer and paint
messages are a little special, but that's a different topic.) That
message gets handled by the normal message queue dispatch process, which
means that the message is handled by the thread that created the
window. THAT'S the key point.
> wx.Timer ends up calling the SetTimer API in Windows (or an equivalent
> in other systems). When the interval expires, SetTimer fires off a
> message to the window that owns the timer.
for completeness's sake, you CAN use threading.Timer if you want, but
rather than call the wx function you want directly, you can make a
call that puts an event on the event stack -- wx.CallAfter it the
easiest way to do it. but if all you're using threads for is a timer,
it makes more sense to use wx.Timer.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
In other words, wx.Timer is based off of the native platform's APIs
meant for getting a callback/message/event after the specified amount of
time. Although at a high-level they seem to provide the same
functionality as a threading.Timer, under the covers they are very
different things.
--
Robin Dunn
Software Craftsman
http://wxPython.org