By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,592 Members | 1,478 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,592 IT Pros & Developers. It's quick & easy.

"The C++ part of the .. Has been deleted, wsTaskBarIcon

P: n/a

I need some help. I cant seem to get rid of this error.

I can program a button that will exit the program and remove the icon in
the taskbar, but I have to tie it to OnTaskBarClose.

OnExit and OnCloseWindow do nothing and leave the icon in the taskbar, I
think I have tried every option, when you double click the icon it gives
you the error.

Traceback (most recent call last):
File "D:/Python24/", line 43, in OnTaskBarActivate
File "D:\Python24\Lib\site-packages\wx-2.5.4-msw-unicode\wx\",
line 11263, in __getattr__
raise PyDeadObjectError(self.attrStr % self._name)
wx._core.PyDeadObjectError: The C++ part of the MyFrame object has been
deleted, attribute access no longer allowed.

When the program runs, you can right click on the icon in the taskbar
and close and it works.
I hardcoded the file > Exit button to do the same thing and that works
However if you click the top right X to just close the window, or on
close that's when the error happens.

How do I get the close to work properly from the default window? I have
been on this same thing for days. Any help would be greatly appreciated.

Heres the code, also attaching it.
from wxPython.wx import *
import sys
import os
ID_ABOUT = 101
ID_EXIT = 102

class MyFrame(wxFrame):
def __init__(self, NULL, ID, title):
wxFrame.__init__(self, NULL, ID, title,
wxDefaultPosition, wxSize(200, 150))
self.SetStatusText("This is the statusbar")

menu = wxMenu()
menu.Append(ID_ABOUT, "&About",
"More information about this program")
menu.Append(ID_EXIT, "E&xit", "Terminate the program")

menuBar = wxMenuBar()
menuBar.Append(menu, "&File");


EVT_MENU(self, ID_ABOUT, self.OnAbout)
EVT_MENU(self, ID_EXIT, self.OnTaskBarClose)
# make the TaskBar icon
self.tbIcon = wxTaskBarIcon()
# FIX ME WITH your Icon
icon = wxIcon('small.ico', wxBITMAP_TYPE_ICO)
self.tbIcon.SetIcon(icon, "It Doesnt work!")
EVT_TASKBAR_LEFT_DCLICK(self.tbIcon, self.OnTaskBarActivate)
EVT_TASKBAR_RIGHT_UP(self.tbIcon, self.OnTaskBarMenu)
EVT_MENU(self.tbIcon, self.TBMENU_CLOSE, self.OnTaskBarClose)
EVT_ICONIZE(self, self.OnIconify)

def OnIconify(self, evt):

def OnTaskBarActivate(self, event):


def OnTaskBarMenu(self, event):
menu = wxMenu()
menu.Append(self.TBMENU_CLOSE, "Close")

def OnOK(self, event):

def OnExit(self, event):
del self.tbIcon

def OnCloseWindow(self, event):
del self.tbIcon

def OnTaskBarClose(self, event):
del self.tbIcon

def OnAbout(self, event):
dlg = wxMessageDialog(self, "This sample program shows off\n"
"frames, menus, statusbars, and this\n"
"message dialog.",
"About Me", wxOK | wxICON_INFORMATION)
def TimeToQuit(self, event):

class MyApp(wxApp):
def OnInit(self):
frame = MyFrame(NULL, -1, "Hello from wxPython")
return true
app = MyApp(0)

Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.