问题
I ran the following python code
import wx
class myframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, title="Hello")
self.InitUI()
def InitUI(self):
menubar = wx.MenuBar()
fileMenu = wx.Menu()
qmi = wx.MenuItem(fileMenu, 100, '&Quit\tCtrl+Q')
qmi.SetBitmap(wx.Image('quit.png', wx.BITMAP_TYPE_ANY).ConvertToBitmap())
fileMenu.AppendItem(qmi)
self.Bind(wx.EVT_MENU, self.OnQuit, id=100)
menubar.Append(fileMenu, '&File')
self.SetMenuBar(menubar)
self.SetSize((250, 200))
self.SetTitle('Icons and shortcuts')
self.Centre()
self.Show(True)
def OnQuit(self, e):
self.Close()
def main():
ex = wx.App()
myframe()
ex.MainLoop()
if __name__ == '__main__':
main()
The above code is throwing the message
qmi.SetBitmap(wx.Image('quit.png', wx.BITMAP_TYPE_ANY).ConvertToBitmap())
File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_core.py", line 2882, in __init__
_core_.Image_swiginit(self,_core_.new_Image(*args, **kwargs))
PyAssertionError: C++ assertion "strcmp(setlocale(LC_ALL, NULL), "C") == 0" failed at ..\..\src\common\intl.cpp(1449) in wxLocale::GetInfo(): You probably called setlocale() directly instead of using wxLocale and now there is a mismatch between C/C++ and Windows locale.
Things are going to break, please only change locale by creating wxLocale objects to avoid this!
I am new to python and completely unable to solve this. Is there anyway to find the solution to this.
I am using python 2.7.10 and wxpython 3.0.2.0 in a windows machine.
回答1:
I had a similar issue that only occurred following a cxFreeze with wxPhoenix. I worried that the solution above could cause issues on a machine that wasn't wx.LANGUAGE_ENGLISH, so instead, I recorded the locale before any imports (which I suspected were changing the locale):
import wx
locale = wx.Locale.GetSystemLanguage()
And then reset it after my imports and after creating the app:
app = wx.App(redirect=False)
app.locale = wx.Locale(locale)
This worked for me.
回答2:
The solution is to modify the locale and it is working. Modified the code as here:
def main():
ex = wx.App()
ex.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
myframe()
ex.MainLoop()
Locale is conflicting with system locale. So modified it in the code for this program.
来源:https://stackoverflow.com/questions/33505916/wx-image-is-throwing-pyassertionerror