of course, this Bind will not help much if the owners of the timers are casually changed !
(in the example it’s a difference of closing tic or tac first, thanks to the OS)
import wx
class Frame(wx.Frame):
def __init__(self, frm, *args, **kwargs):
super().__init__(*args, **kwargs)
self.frm = frm
self.timer = wx.Timer()
print(f'{self.Title} timer is {id(self.timer)}')
self.timer.SetOwner(self)
self.timer.Start(1000)
self.Bind(wx.EVT_TIMER, self.OnTimer)
self.Bind(wx.EVT_WINDOW_DESTROY,
lambda _: self.timer.Destroy())
self.Show()
def OnTimer(self, evt):
print(f'{evt.GetEventObject().Title} from timer {id(evt.GetTimer())}')
if self.frm:
self.timer.SetOwner(self.frm)
print(f'timer owner of {self.Title} switched to {self.frm.Title}')
if __name__ == "__main__":
app = wx.App()
frm = Frame(None, None, title='tic')
Frame(frm, None, title='tac')
app.MainLoop()