【问题标题】:wx.Image is throwing PyAssertionErrorwx.Image 正在抛出 PyAssertionError
【发布时间】:2015-11-03 17:53:39
【问题描述】:

我运行了以下 python 代码

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()

上面的代码是在抛出消息

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!

我是 python 新手,完全无法解决这个问题。 有没有办法解决这个问题。

我在 windows 机器上使用 python 2.7.10 和 wxpython 3.0.2.0。

【问题讨论】:

    标签: python python-2.7 wxpython wxwidgets


    【解决方案1】:

    我有一个类似的问题,它只发生在使用 wxPhoenix 的 cxFreeze 之后。我担心上面的解决方案可能会在不是 wx.LANGUAGE_ENGLISH 的机器上引起问题,所以我在任何导入之前记录了语言环境(我怀疑这会改变语言环境):

    import wx
    locale = wx.Locale.GetSystemLanguage()
    

    然后在我的导入和创建应用程序之后重置它:

    app = wx.App(redirect=False)
    app.locale = wx.Locale(locale)
    

    这对我有用。

    【讨论】:

      【解决方案2】:

      解决方案是修改语言环境并且它正在工作。 修改代码如下:

      def main():
          ex = wx.App()
          ex.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
          myframe()
          ex.MainLoop()
      

      区域设置与系统区域设置冲突。所以在这个程序的代码中修改了。

      【讨论】:

        猜你喜欢
        • 2011-01-02
        • 2018-04-21
        • 1970-01-01
        • 2019-06-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多