代码之家  ›  专栏  ›  技术社区  ›  ruohola

任何文本字段中的右键单击上下文菜单都会导致程序崩溃,并出现错误“m\u menuDepth>0”?

  •  0
  • ruohola  · 技术社区  · 7 年前

    我注意到,当右键单击wxPython小部件中的文本字段时,如果用户选择 Insert Unicode control character example image

    wx._core.wxAssertionError: C++ assertion "m_menuDepth > 0" failed at ..\..\src\msw\toplevel.cpp(1545) in wxTopLevelWindowMSW::DoSendMenuOpenCloseEvent(): No open menus?
    
    The above exception was the direct cause of the following exception:
    
    SystemError: <class 'wx._core.CommandEvent'> returned a result with an error set
    

    下面是一个抛出错误的示例代码;

    import wx
    
    
    class Program(wx.Frame):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
    
            self.panel = wx.Panel(self)
            self.sizer = wx.GridBagSizer(0, 0)
            self.panel.SetSizer(self.sizer)
    
            self.text_ctrl = wx.TextCtrl(self.panel)
            self.sizer.Add(self.text_ctrl, wx.GBPosition(0, 0))
    
            # Needed, because there probably has to be some events which
            # can be processed for the error to show before closing the program.
            # Without this the error only appears after exiting.
            self.text_ctrl.Bind(wx.EVT_TEXT, lambda e: print("text changed"))
    
            self.sizer.Layout()
            self.Show()
    
    
    app = wx.App()
    program = Program(parent=None)
    app.MainLoop()
    

    如果不从头开始重做上下文菜单,不完全禁用上下文菜单,不包装大量内容,如何防止此错误 try-except (真是个坏习惯 wx._core.wxAssertionError ,因为它们通常是致命的)?

    编辑:

    操作系统: Win 10 Enterprise 2016 LTSB/Win 10 Pro(在两者上都进行了测试)

    来自pip3的4.0.2/4.0.3(在两者上测试)

    Python版本和源代码: Python 3.6.5库存

    1 回复  |  直到 7 年前
        1
  •  0
  •   ruohola    7 年前

    这是wxPython的一个bug,将在将来的版本中修复。

    https://github.com/wxWidgets/Phoenix/issues/992

    推荐文章