wxPython;右键单击任何文本字段中的上下文菜单会使程序崩溃并出现错误 "m_menuDepth > 0"?
wxPython; right click context menu in any text field can crash program with the error "m_menuDepth > 0"?
我注意到当右键单击 wxPython 小部件中的文本字段时,如果用户选择 Insert Unicode control character
选项并插入任何这些字符,程序将抛出这个错误;
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(均已测试)
wxPython 版本和来源: 来自 pip3 的 4.0.2 / 4.0.3(两者均已测试)
Python 版本&来源: Python 3.6.5 stock
这是 wxPython 的一个错误,将在未来的版本中修复。
我注意到当右键单击 wxPython 小部件中的文本字段时,如果用户选择 Insert Unicode control character
选项并插入任何这些字符
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(均已测试)
wxPython 版本和来源: 来自 pip3 的 4.0.2 / 4.0.3(两者均已测试)
Python 版本&来源: Python 3.6.5 stock
这是 wxPython 的一个错误,将在未来的版本中修复。