MacOS 上 wxPython 应用程序的 Dock 问题
MacOS 上的扩展坞存在问题。 在停靠图标的上下文菜单中,有 2 个项目:MacOS 的“标准退出”和一些我没有添加的菜单项“退出”。 那个退出,不是我的,是有效的,并且与我的方法相关联:
class TrayIcon(wx.TaskBarIcon):
def make_menu(self):
self.menu = wx.Menu()
item = self.menu.Append(wx.ID_EXIT,"Exit", "Exit from application")
self.menu.Bind(wx.EVT_MENU, self.on_menu_exit, item)
def CreatePopupMenu(self):
self.make_menu()
return self.menu
如你所见,我将其称为“退出”,但我看到“退出”,但它仍然按我的方法处理。
退出系统,它不起作用,当我选择它时,什么也没有发生,但应用程序的下一步操作会导致此错误消息:
文件 “/var/tmp/wxWidgets/wxWidgets-13~231/2.6/DSTROOT/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode/wx/_core. py", 第 14501 行,在 getattr wx._core.PyDeadObjectError:C++ 部分 Main 对象已被删除,不再允许属性访问。
我做错了什么? 谢谢
There is a problem with dock on MacOS.
In context menu at dock-icon there are 2 items: Standart Quit of MacOS and some menu item Quit, that i didn't add.
That Quit, that not mine, is works and associated with my method:
class TrayIcon(wx.TaskBarIcon):
def make_menu(self):
self.menu = wx.Menu()
item = self.menu.Append(wx.ID_EXIT,"Exit", "Exit from application")
self.menu.Bind(wx.EVT_MENU, self.on_menu_exit, item)
def CreatePopupMenu(self):
self.make_menu()
return self.menu
As you see, i сall it "Exit", but i see "Quit", but it still handles by my method.
And Quit that is system, it won't work, when i select it, nothing happens, but next actions with application lead to this error message:
File
"/var/tmp/wxWidgets/wxWidgets-13~231/2.6/DSTROOT/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode/wx/_core.py",
line 14501, in getattr wx._core.PyDeadObjectError: The C++ part of
the Main object has been deleted, attribute access no longer allowed.
What did I do wrong?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原因可能是您没有保留对
item
的引用。它绑定在self.menu.Bind
中,但您无需在 Python 代码中保留引用。因此,Python 垃圾收集器发现这个 wx.MenuItem 不再被引用(在 Python 代码中),因此将其删除。 Wx 的清理代码 (__del__
) 被调用,并且该对象也在 C++ 代码中被删除,尽管它仍在使用中!。因此,当您单击菜单项时,它会尝试将单击的菜单项与(届时)删除的菜单项进行匹配,并抛出上述PyDeadObjectError
。要解决此“错误”,只需保留对 wx.MenuItem 的引用即可:The cause is probably that your are not keeping a reference to
item
. It is bound inself.menu.Bind
, but you do not keep a reference in the Python code. So the Python garbage collector sees thiswx.MenuItem
that isn't referenced anymore (within the Python code), so it is deleted. Wx's clean up code (__del__
) is called and the object is also removed in the C++ code, although it is still in use!. So when you click the menu item, it tries to match the clicked menu item with the (by then) removed menu item and it throws the aforementionedPyDeadObjectError
. To work around this 'bug', simply keep a reference to thewx.MenuItem
: