0

このコードに問題があります:

import wx
class Example(wx.Frame):

    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs) 

        self.InitUI()

    def InitUI(self):    

        toolbar = self.CreateToolBar()
        qtool = toolbar.AddLabelTool(wx.ID_ANY, 'Quit', wx.Bitmap('texit.png'))
        toolbar.Realize()

        self.Bind(wx.EVT_TOOL, self.OnQuit, qtool)

        self.SetSize((250, 200))
        self.SetTitle('Simple toolbar')
        self.Centre()
        self.Show(True)



    def OnQuit(self, e):
        self.Close()

def main():

    ex = wx.App()
    Example(None)
    ex.MainLoop()    


if __name__ == '__main__':
    main()

実行すると、次のようになります。

Traceback (most recent call last):
  File "...\maintest.py", line 34, in <module>
    main()
  File "...\painter3D\maintest.py", line 29, in main
    Example(None)
  File "...\maintest.py", line 8, in __init__
    self.InitUI()
  File "...\maintest.py", line 14, in InitUI
    toolbar.Realize()
  File "C:\Python27\lib\site-packages\wx-2.9.4-msw\wx\_controls.py", line 3797, in Realize
    return _controls_.ToolBarBase_Realize(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "Assert failure" failed at ..\..\src\msw\toolbar.cpp(796) in wxToolBar::Realize(): invalid tool button bitmap

私が使う:

Win7
Python2.7
wxPython2.8 unicode

私は答えに感謝します。

4

2 に答える 2

0

Try:

import wx
class Example(wx.Frame):

    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs) 

        self.InitUI()

    def InitUI(self):    

        toolbar = self.CreateToolBar()
        myimage = wx.Image('texit.png')
        qtool = toolbar.AddLabelTool(wx.ID_ANY, 'Quit', wx.BitmapFromImage(myimage))
        toolbar.Realize()

        self.Bind(wx.EVT_TOOL, self.OnQuit, qtool)

        self.SetSize((250, 200))
        self.SetTitle('Simple toolbar')
        self.Centre()
        self.Show(True)



    def OnQuit(self, e):
        self.Close()

def main():

    ex = wx.App()
    Example(None)
    ex.MainLoop()    


if __name__ == '__main__':
    main()

maybe this can help you :D

于 2013-07-22T03:44:49.460 に答える