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()
from wxPython.wx import * import sys import os import wx import tkMessageBox import commands #------------------------------------------------------------------------= class MyDialog(wxDialog): def __init__(self): wxDialog.__init__(self, NULL, -1, "Pasteaway v1.0 Alex Nordhus", wxPoint(-1,-1), wxSize(380,300)) # wxDIALOG_MODELESS|wxDEFAULT_DIALOG_STYLE) #------------------------------- # contents of the Dialog wxStaticText(self, -1, "Press OK to Minimize me. Exit to Quit", wxPoint(10, 20)) wxStaticText(self, -1, "Double-click on the taskbar icon to show me again.", wxPoint(10, 40)) button = wxButton(self, 10, "Visit Us", wxPoint(10, 55), wxSize(60, 25)) okButton = wxButton(self, wxID_OK, "Minimize", wxPoint(100, 240), wxSize(80, 25)) exitButton = wxButton(self, wxID_EXIT, "Exit", wxPoint(185, 240), wxSize(80, 25)) okButton.SetDefault() self.Centre(wxBOTH) EVT_BUTTON(self, 10, self.OnVisit) EVT_BUTTON(self, wxID_OK, self.OnOK) EVT_BUTTON(self, wxID_EXIT, self.OnTaskBarClose) # make the TaskBar icon self.tbIcon = wxTaskBarIcon() icon = wxIcon('small.ico', wxBITMAP_TYPE_ICO) self.tbIcon.SetIcon(icon, "PasteAway!") 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 OnVisit(self, evt): os.system('start iexplore http://24.162.131.55/pasteaway') 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): sys.exit() self.Close(true) def OnCloseWindow(self, event): sys.exit() del self.tbIcon # ensure the tbIcon is cleaned up... wxGetApp().ProcessIdle() def OnTaskBarClose(self, event): del self.tbIcon sys.exit() #------------------------------------------------------------------------= class MyApp(wxApp): def OnInit(self): frame = MyDialog() self.dlg = MyDialog() self.dlg.Show(true) self.SetTopWindow(self.dlg) return true #class MyApp(wxApp): # def OnInit(self): # self = MyFrame() # self.Show(true) # self.SetTopWindow(self) # return true #------------------------------------------------------------------------= def main(): app = MyApp(0) # app = MyFrame(0) app.MainLoop() if __name__ == '__main__': main()
-- http://mail.python.org/mailman/listinfo/python-list