我想要在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