0
votes

How is it possible to add menu items to the system menu of a frame in wxPython/wxWidgets?
(I'm talking about the menu that appears when clicking on the application icon in Windows - the one with Minimize, Maximize, Close, ...).

I want to add a menu item of my own for a simple application that doesn't require a full blown top menu.

A Windows-only solution, if one exists (and is simple enough), would be useful too.

1

1 Answers

1
votes

I don't think wxWidgets/wxPython allows you to manipulate the system menu, with a few exceptions that are not sufficient for what you want:

  • You can remove the system menu by passing a style flag to the wx.Frame: style=wx.DEFAULT_FRAME_STYLE & ~wx.SYSTEM_MENU

  • On Mac OS X, menu items with ids such as wx.ID_EXIT and wx.ID_HELP are moved into the application menu.

I tried to bind the wx.EVT_MENU_OPEN event and although the event handler is invoked, the passed event doesn't contain anything useful on Windows. The code below prints 'None 0' when I open the Frame's system menu:

import wx

class Frame(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(Frame, self).__init__(*args, **kwargs)
        self.Bind(wx.EVT_MENU_OPEN, self.onMenuOpen)

    def onMenuOpen(self, event):
        print event.GetMenu(), event.GetMenuId()
        event.Skip()


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