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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

a.link
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()


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Tim Roberts
On Oct 13, 2018, at 6:14 AM, a.link <[hidden email]> wrote:

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.
— 
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

a.link
Thank you, that really helped!

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.