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

A

Alex Nordhus

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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top