wx.MenuItem.SetSubMenu(menu) works, while wx.MenuItem(subMenu=menu) doesn't

App crashes w/o even showing a window when wx.MenuItem(subMenu=wx.Menu()) is used. Below is fully working code that reproduces the issue. Do you think this is a bug, or am I doing something wrong? I’m using Windows 7 64 bit, Python 3.6.6 64 bit, wxPython 4.0.3.

BTW, I’m using such non-traditional way to construct menu so that to be able to use bitmaps in submenus, rather than menu items alone (https://forums.wxwidgets.org/viewtopic.php?t=32280).

import wx

app = wx.App(0)
frame = wx.Frame(None)

menu = wx.Menu()

itm0 = wx.MenuItem(None, -1, ‘item #0’)
menu.Append(itm0)

itm1 = wx.MenuItem(None, -1, ‘item #1’)
menu.Append(itm1)

itmX = wx.MenuItem(None, -1, ‘item #X’); itmX.SetSubMenu(wx.Menu()) # works.

itmX = wx.MenuItem(None, -1, ‘item #X’, subMenu = wx.Menu()) # doesn’t work.

menu.Append(itmX)

frame.Bind(wx.EVT_CONTEXT_MENU, lambda event: frame.PopupMenu(menu))

frame.Show()
app.MainLoop()

``

App crashes w/o even showing a window when wx.MenuItem(subMenu=wx.Menu()) is used. Below is fully working code that reproduces the issue. Do you think this is a bug, or am I doing something wrong? I’m using Windows 7 64 bit, Python 3.6.6 64 bit, wxPython 4.0.3.

BTW, I’m using such non-traditional way to construct menu so that to be able to use bitmaps in submenus, rather than menu items alone

This is not really “non-traditional”. It looks quite normal.

itmX = wx.MenuItem(None, -1, ‘item #X’); itmX.SetSubMenu(wx.Menu()) # works.

itmX = wx.MenuItem(None, -1, ‘item #X’, subMenu = wx.Menu()) # doesn’t work.

menu.Append(itmX)

``

Your code also fails on MacOS. The Append option with subMenu has been deprecated; if I replace that line with the equivalent replacement:
menu.AppendSubMenu( wx.Menu(), ‘item #X’ )

then it works fine.

···

On Oct 13, 2018, at 6:14 AM, a.link 8day.spam@gmail.com wrote:


Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Thank you, that really helped!