wx Menu disappears from frame when shown as a popup

Posted by Adam Fraser on Stack Overflow See other posts from Stack Overflow or by Adam Fraser
Published on 2010-03-24T02:29:05Z Indexed on 2010/03/24 2:33 UTC
Read the original article Hit count: 324

Filed under:
|
|

I'm trying to create a wx.Menu that will be shared between a popup (called on right-click), and a sub menu accessible from the frame menubar. The following code demonstrates the problem.

If you open the "MENU>submenu" from the menubar the item "asdf" is visible. If you right click on the frame content area, "asdf" will be visible from there as well... however, returning to the menubar, you will find that "MENU>submenu" is vacant. Why is this happening and how can I fix it?

import wx
app = wx.PySimpleApp()
m = wx.Menu()
m.Append(-1, 'asdf')

def show_popup(evt):
   ''' R-click callback '''
   f.PopupMenu(m, (evt.X, evt.Y))

f = wx.Frame(None)
f.SetMenuBar(wx.MenuBar())
frame_menu = wx.Menu()
f.MenuBar.Append(frame_menu, 'MENU')
frame_menu.AppendMenu(-1,'submenu', m)
f.Show()
f.Bind(wx.EVT_RIGHT_DOWN, show_popup)
app.MainLoop()

Interestingly, appending the menu to MenuBar works, but is not the behavior I want:

import wx
app = wx.PySimpleApp()
m = wx.Menu()
m.Append(-1, 'asdf')

def show_popup(evt):
   f.PopupMenu(m, (evt.X, evt.Y))

f = wx.Frame(None)
f.SetMenuBar(wx.MenuBar())
f.MenuBar.Append(m, 'MENU')
f.Show()
f.Bind(wx.EVT_RIGHT_DOWN, show_popup)
app.MainLoop()

© Stack Overflow or respective owner

Related posts about wxpython

Related posts about menus