我想要在Preferences
菜单项前面有一个漂亮的齿轮位图。这是我认为它应该被编码:MenuItem位图引发断言失败...
menubar = wx.MenuBar()
fileMenu = wx.Menu()
preferences = wx.MenuItem(text="Preferences",
helpString="Opens preferences dialog.",
kind=wx.ITEM_NORMAL)
gear = wx.Bitmap(os.path.join(os.path.dirname(__file__), 'gear.png'))
preferences.SetBitmap(gear)
self.shcfg = fileMenu.Append(preferences)
然而,这是错误的,因为我得到一个
Traceback (most recent call last):
File "gui.py", line 193, in <module>
GUI(None)
File "gui.py", line 117, in __init__
self.InitUI()
File "gui.py", line 129, in InitUI
preferences.SetBitmap(gear)
wx._core.wxAssertionError: C++ assertion "Assert failure" failed at /tmp/pip-build-sc_vd1aj/wxPython/ext/wxWidgets/src/gtk/menu.cpp(729) in SetBitmap(): only normal menu items can have bitmaps
我在做什么错?
引发'AttributeError:'MenuItem'对象没有属性'SetId'' ...我正在运行Python 3,而不是2。对代码进行黑客处理以便编译引发与问题中相同的错误。 ☹ – Sardathrion
您不能使用python3运行wxpython(经典)。如果你正在运行wxpython phoenix,据我所知,它仍然不存在!我的答案愉快地运行使用wxpython 3.0.2.0 gtk2(经典)与Python 2.7.12我想这是所有的版本;) –
我正在运行wxpython phoenix。所以我想我不能那样做。别担心。 – Sardathrion