Use StaticBitmap with .icns file: SetIcon segfaults


I am trying to use display a .icns inside my GUI, but am having problems getting my code to run.
Is there any way to do this without converting to png first?

This is my example code (run on MacOS):

Python 3.12.3 on darwin, wxPython 4.2.1 osx-cocoa (phoenix) wxWidgets

import wx

import faulthandler

class MyFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent)
        self.SetSize((400, 200))
        self.SetTitle("Icon Test")
        self.panel = wx.Panel(self, wx.ID_ANY)
        sizer = wx.BoxSizer(wx.VERTICAL)

        sbm = wx.StaticBitmap()
        icon = wx.Icon()
        icns_path = "/System/Applications/"
        icon.LoadFile(icns_path, type=wx.BITMAP_TYPE_ICON)
        # icon.LoadFile(icns_path, type=wx.BITMAP_TYPE_ICO)
        sbm.SetIcon(icon)  # segfaults here
        sizer.Add(sbm, 0)


if __name__ == "__main__":
    app = wx.App()
    frame = MyFrame(None)


Fatal Python error: Segmentation fault

Current thread 0x00000002010ae600 (most recent call first):
  File "/private/tmp/", line 20 in __init__
  File "/private/tmp/", line 29 in <module>

Extension modules: wx._core (total: 1)
zsh: segmentation fault  python3

Attached .icns file for non-Mac users: (68.7 KB)

You are not passing a parent control to the StaticBitmap.

Instead of:

    sbm = wx.StaticBitmap()


    sbm = wx.StaticBitmap(self.panel)

Tested using Python 3.11.9 and wx.Python 4.2.1 osx-cocoa (phoenix) wxWidgets on Sonoma 14.5

Thank you so much - such a silly mistake from me!