Hi, Posts
While playing with an event watcher, I ran into a mysterious crash. The first code works fine, but the second code has a problem. If you close the Event Watcher window and press the button, the program will crash silently. I couldn’t find out where this problem comes from. Am I overlooking something?
- The following code works fine.
import wx
import wx.lib.eventwatcher as ew
class TestPanel(wx.Panel):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.btn = wx.Button(self, label="Hello, wxPython!")
self.btn.Bind(wx.EVT_BUTTON, print)
if __name__ == "__main__":
app = wx.App()
frm = wx.Frame(None)
frm.panel = TestPanel(frm)
watcher = ew.EventWatcher(frm) # no crash after closing window
watcher.watch(frm.panel.btn)
watcher.Show()
frm.Show()
app.MainLoop()
- The following code crashes.
import wx
import wx.lib.eventwatcher as ew
class TestPanel(wx.Panel):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.btn = wx.Button(self, label="Hello, wxPython!")
watcher = ew.EventWatcher(None) # silent crash after closing window
watcher.watch(self.btn)
watcher.Show()
## close -> unwatch => crash
self.btn.Bind(wx.EVT_BUTTON, print)
if __name__ == "__main__":
app = wx.App()
frm = wx.Frame(None)
frm.panel = TestPanel(frm)
frm.Show()
app.MainLoop()