TypeError: MenuItem(): argument 2 has unexpected type 'StandardID' when running the demo

A recent update (Python 3.11? wxWidgets 3.2.2? sip 6.7.4? ) breaks “MenuItem” on MSW.

A colleague (MSW) and I (Linux GTK) just compiled from source the latest wxPython and included wxWidgets from the master branch.

On MSW something is broken because we get this error when trying to run the demo.

PS C:\Users\myuser\Phoenix\demo> python .\demo.py
Traceback (most recent call last):
  File "C:\Program Files\MyApp\WPy64-31120b3\python-3.11.2.amd64\Lib\site-packages\wx\core.py", line 2346, in Notify
  File "C:\Program Files\MyApp\WPy64-31120b3\python-3.11.2.amd64\Lib\site-packages\wx\core.py", line 3552, in Notify
    self.result = self.callable(*self.args, **self.kwargs)
  File "Z:\Phoenix\demo\Main.py", line 2605, in ShowMain
    frame = wxPythonDemo(None, "wxPython: (A Demonstration)")
  File "Z:\Phoenix\demo\Main.py", line 1497, in __init__
  File "Z:\Phoenix\demo\Main.py", line 1664, in BuildMenuBar
    exitItem = wx.MenuItem(menu, wx.ID_EXIT, 'E&xit\tCtrl-Q', 'Get the heck outta here!')
TypeError: MenuItem(): argument 2 has unexpected type 'StandardID'

On Linux GTK things work as expected. We are both using Python 3.11.2.

My colleague has experience compiling wxPython/wxWidgets from source on MSW so the broken demo suggests that something has changed.

We welcome any thoughts. Thank you.

We were able to build just fine on a different MSW machine. We still have not figured out what the issue was. We are suspecting that somehow through the various updates to MSW and Visual Studio we end up calling an outdated DLL somehow.

How about sharing. Maybe a 3.11.x wheel for windows and something for Ubuntu.

I ran into the same problem on Windows 10 with

  • Python 3.11.3
  • sip 6.7.9 or 6.7.8
  • wx version 4.2.1a1 msw (phoenix) wxWidgets 3.2.2

Build with MinGW (using Git Bash).

I will appreciate eternity if you can find out how to fix it! :pray:
This is the test code:

import wx

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

        self.menubar = wx.MenuBar()
        menu = wx.Menu()
        if 0:
            ## OK
            menu_item = menu.Append(wx.ID_EXIT, "Exit\tCtrl-w")
            ## Python 3.11 - NG
            ## TypeError: MenuItem(): argument 2 has unexpected type 'StandardID'
            ## or
            ## TypeError: MenuItem(): argument 2 has unexpected type 'int'
            menu_item = wx.MenuItem(menu, wx.ID_EXIT, "Exit\tCtrl-w")

        self.Bind(wx.EVT_MENU, lambda v: self.Close(), menu_item)
        self.menubar.Append(menu, "File")

if __name__ == "__main__":
    app = wx.App()
    frm = Frame(None)

which gives,

Traceback (most recent call last):
  File "C:\usr\home\lib\py-site\test-phoenix\issue_wxpy311-menuitem.py", line 41, in <module>
    frm = Frame(None)
  File "C:\usr\home\lib\py-site\test-phoenix\issue_wxpy311-menuitem.py", line 29, in __init__
    menu_item = wx.MenuItem(menu, wx.ID_EXIT, "Exit\tCtrl-w")
TypeError: MenuItem(): argument 2 has unexpected type 'StandardID'

I would be happy to upload our Windows wheel to a public location. Any suggestions of location? Of course, best in the long term would be if @Robin or someone with the right privileges can add Python 3.11 to the snapshop builds that get automatically produced at Index of /Phoenix/snapshot-builds