Hi, My wx application work as expected but on exit dont destroy Timer object which calling StaticText. Object still running and doing console errors as in subject.
How to destroy wx application without errors?
So far, I’ve solved it with following code:
If you close the second frame first, then the first frame, then you get two messages:
EVT_CLOSE Second frame
EVT_CLOSE First frame
But if you close the first frame, then you only get one:
EVT_CLOSE First frame
So if you have a timer on the second frame, it doesn’t get an EVT_CLOSE event for that frame if the frame is destroyed by the parent, and in that case it will fail stop the timer, and you will get intermittent crashes because the expired timer tries to message a destroyed object.
Instead, use EVT_WINDOW_DESTROY:
class MyFrame(wx.Frame):
...
self.Bind(wx.EVT_WINDOW_DESTROY, self._OnWindowDestroy)
def _OnWindowDestroy(self, event):
event.Skip()
self.timer.Stop()
In that case I hope you realise that self._run can’t touch any of your wx.Window objects. That’s the advantage of wx.Timer: You can update the UI in the timer event, you can’t do that with threading.Timer.
wx.EVT_WINDOW_DESTROY is a command event and thus propagates upwards, so if the frame hangs somewhere in the middle of a hierarchy in which not all windows catch the destroy or, like here, skip it nicely then the identity must be checked (it’s the invers case, when the timer stops but the frame is still alive)
excuse me, but I think this Skip() is another oddity: on the one hand you restrict the source & on the other the event is sent on !?
the docu recommends to generally skip non-command events but even there I am usually selective (EVT_SIZE is an exception)
they used to say the app has turned into a VW: it runs and runs and… but after that diesel gate and joining force with MS I expect any day my laptop to fume
Skip() is about not accidentally disabling some other functionality that relies on the event. It may be completely pointless here when you think it through, but I include it precisely so that I don’t have to think it through.
Well, that’s not quite my cup of tea & I hope the devs don’t fall victim to it (in quite a few places one would get the boot, but they are by far not the majority)
happy coding
P.S.:
I just came across a nice counter example: a plot of mine using lib.plot has a wx.Choice and if the event wx.EVT_CHOICE doesn’t get intercepted the plot flickers, not always but for some selections, a joy for when one has left the customer…