【发布时间】:2012-07-20 20:10:19
【问题描述】:
我最近创建了一段代码,当我关闭它时,它总是向我显示两次这样的消息:
(python:11712): LIBDBUSMENU-GLIB-WARNING **: 试图移除一个不相信我们是它的父母的孩子。
我想要摆脱那个警告。 这段代码重现了这种行为(关闭时出现一次消息):
import wx
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title="Sample")
menuBar = wx.MenuBar()
filemenu = wx.Menu()
filemenu.Append(wx.ID_ANY,"&Pass")
menuBar.Append(filemenu,"&File")
self.SetMenuBar(menuBar)
app = wx.PySimpleApp()
frame = MyFrame(None)
frame.Show()
app.MainLoop()
它运行良好,但当我关闭应用程序时会出现警告消息。 这是一条仅限 Linux 的消息,当我在 Windows 上尝试时没有显示任何内容。
我使用的一种解决方法是在我的框架中绑定一个关闭事件处理程序
def __init__(self, parent):
... # Previous code here
self.Bind(wx.EVT_CLOSE, self.OnClose)
并制作这样的事件处理程序
def OnClose(self, evt):
for menu in self.GetMenuBar().GetMenus(): # (wx.Menu, caption) tuples
menu[0].Destroy() # Bad parents won't remove you, you'll DIE before!!!
evt.Skip()
在 Linux 上的那个简单应用程序中运行良好,但是当我在 Windows 上尝试时它崩溃了。所以我想看看在 Linux 上运行时发生了什么,替换行
menu[0].Destroy()
到
print menu[0].Parent
它告诉我“无”作为答案。但是我做不到:
menu[0].Parent = self
两者都没有:
menu[0].Parent = self.GetMenuBar()
由于两者都会引发 TypeError:
TypeError:在方法“Menu_SetParent”中,预期参数 2 类型为“wxMenu *”
【问题讨论】:
标签: windows linux user-interface menu wxpython