[wxPython-users] Event Handling Anomaly
Bob Klahn
bobstones at comcast.net
Mon Dec 3 08:44:09 PST 2007
Mark, FWIW, no error occurs when I run your code, whether or not I
select something from the list box.
I'm running wxPython 2.8.4.0 with Python 2.5.1 under Windows XP SP2.
Bob
At 11:30 AM 12/3/2007, Mark Erbaugh wrote:
>I've run into an anomaly that can be demonstrated with this code:
>
>################################################################
>
>import wx
>
>class Frame(wx.Frame):
>
> def __init__(self, *args, **kwds):
> wx.Frame.__init__(self, *args, **kwds)
>
> # reverse the following to lines to fix
> self.st = wx.StaticText(self, -1, size=(40,-1))
> self.lb = wx.ListBox(self, -1, choices=['one','two','three'])
>
> sz = wx.BoxSizer(wx.HORIZONTAL)
> sz.Add(self.lb, 0)
> sz.Add(self.st, 0)
> self.SetSizer(sz)
> self.Fit()
>
> # self.Bind(wx.EVT_LISTBOX, self.onLB, self.lb) # okay on exit
> self.lb.Bind(wx.EVT_LISTBOX, self.onLB) # error on exit
>
> def onLB(self, event):
> self.st.SetLabel(self.lb.GetStringSelection())
>
>
>if __name__ == "__main__":
> app = wx.PySimpleApp(0)
> Frame(None, -1, "").Show()
> app.MainLoop()
>
>################################################################
>
>When you run this example, if you select an item in the wx.ListBox, you
>will get an error when you exit the app:
>
>wx._core.PyDeadObjectError: The C++ part of the StaticText object has
>been deleted, attribute access no longer allowed.
>
>You don't get the error if you just launch the app and exit without
>selecting an item in the wx.ListBox
>
>You can eliminate the error by switching the order of the two lines
>creating the wx.StaticText and the wx.ListBox.
>
>You can also eliminate the error by binding the event handler to the
>wx.Frame instead of to the wx.ListBox.
>
>It seems that if an event handler is bound to it, the wx.ListBox
>triggers the handler when it is being destroyed.
>
>This is with Python 2.4.3, wxPython 2.8.7.1, Ubuntu Dapper.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
>For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
>
>
>--
>No virus found in this incoming message.
>Checked by AVG Free Edition.
>Version: 7.5.503 / Virus Database: 269.16.13/1165 - Release Date:
>12/2/2007 8:34 PM
More information about the wxpython-users
mailing list