You can bypass a timer update by finding which window has the focus (using FindFocus
) and comparing this to your TextCtrl window. Then, if your TextCtrl has the focus you can leave it alone. Here's an example:
import wx
class TestFrame(wx.Frame):
def __init__(self):
self.count = 0
wx.Frame.__init__(self, None, -1, "test frame", size=(200, 100))
self.panel = wx.Panel(self, -1)
button = wx.Button(self.panel, -1, "b", pos=(10, 40))
self.text = wx.TextCtrl(self.panel, -1, `self.count`, size=(50, 25))
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.incr_text)
self.timer.Start(1000)
def incr_text(self, event):
self.count += 1
f = self.FindFocus()
if not f==self.text:
self.text.SetValue(`self.count`)
if __name__=="__main__":
app = wx.PySimpleApp()
TestFrame().Show()
app.MainLoop()