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/simple.py", line 43, in OnTaskBarActivate
self.Show(true)
File "D:\Python24\Lib\site-packages\wx-2.5.4-msw-unicode\wx\_core.py",
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
too.
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.CreateStatusBar()
self.SetStatusText("This is the statusbar")

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

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

self.SetMenuBar(menuBar)

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):
self.Hide()

def OnTaskBarActivate(self, event):
self.Show(true)

TBMENU_CLOSE = 1001

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

def OnOK(self, event):
self.Show(false)

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

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

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

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)
dlg.ShowModal()
dlg.Destroy()
def TimeToQuit(self, event):
self.Destroy()

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

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.