Please Hlp with msg: "The C++ part of the StaticText object has been deleted"

python newbie mesteve_b at
Sun Sep 26 08:26:41 CEST 2004

I have  a wxPython app which dump errors when I close it ( in
 the debug output at bottom of Komodo, when I close my app.  )

Where I got the code for my GUI:
   Straight from the file which comes with the samples:
C:\Python23\Lib\site-packages\wx\samples\wxProject\ ----

It basically consists of  a splitterwindow, and  I have a wxPanel
on the left side, which is set to a vertical box sizer.  I used
the Add function of the sizer to simply add a wxStaticText control
at the very top.
The bottom half of this same left panel is a tree.
( u can ignore the *right* side of the splitter.. nothing exciting is
happening.. it's the same as in the sample ,
just a multilined edit contrl)

Anyway, when I click on a node of this tree, I change the text of the
static text control at top, to the text of the node. It actually works,
but when I close the app I get this:
The stack trace:
Traceback (most recent call last):
  File "E:\MyProjects1\python\backup\", line 294, in
  File "C:\Python23\Lib\site-packages\wx\", line 10617, in
    raise PyDeadObjectError(self.attrStr % self._name)
wx._core.PyDeadObjectError: The C++ part of the StaticText object has been
deleted, attribute access no longer allowed.

Here's how I add the wxStaticBox: ------------------------
# ok, first, the code below is actually in this __init__  function
class main_window(wxFrame):
    def __init__(self, parent, id, title):
        wxFrame.__init__(self, parent, -1, title, size = (650, 500),

# first the left panel
# -------------------
self.MyLeftPanel = wxPanel(splitter,10004) #<--a random number I used
didn't want to use -1
self.MyLeftPanel.SetDimensions(0, 0, 100, 220)
self.leftSizer=wxBoxSizer(wxVERTICAL) # the sizer is born

# then add the static text
# -------------------
self.testLabel = wxStaticText(self.MyLeftPanel,self.aNewID,'test label')

Here's how I code the event handler: ------------------

def OnNodeChanged(self,event):
        item = self.tree.GetSelection()
        if (self.tree.ItemHasChildren(item) == 0):
# The commented-out line works too.. the static text does change
# to the static of the node --- very nice, if it weren't
# for the error when you close the app.

Any suggestions would be great.

 Here's the kicker:
Try running C:\Python23\Lib\site-packages\wx\samples\wxProject\
yourself.  (but first remove, say, the editor on the right side,
 add a panel and a sizer,and then add a statictext control
 and add a tree handler to set the label). And it will work
fine. No error dump when you close it!

I double and triple checked that I am doing the same thing as in the
original file. I don't want to dump my own py file, and start over
with the original sample file. i've written too much probably for that.

WX:  wxPython WIN32-
OS:  Windows XP
PYTHON:   From, Version2.3

More information about the Python-list mailing list