jibian6343 2017-11-14 03:18 采纳率: 0%
浏览 2292

学习python中的gui遇到的,AddSimpleTool()和wx.Image()不能出现图片

 import wx
class frame(wx.Frame):
    def __init__(self,superion):
        wx.Frame.__init__(self,superion,-1,size=(400,300))
        panel=wx.Panel(self)
        self.statusBar=self.CreateStatusBar()
        toolbar=self.CreateToolBar()
        toolbar.AddSimpleTool(11,wx.Image('C:\Python27\Lib\site-packages\wx\lib\pdfviewer\bitmaps\Save.png',wx.BITMAP_TYPE_PNG).ConvertToBitmap(),"Open","Click it to open a file.")
        toolbar.Realize()
        wx.ECT_TOOL(self,11,self.OnToolOpen)
        menuBar=wx.MenuBar()
        menul=wx.Menu()
        menul.Append(101,'&New','Create a New File')
        menul.Append(102,'&Open','')
        menul.Append(103,'&Close','')
        menul.AppendSeparator()
        menul.Append(104,'&Close All','Close All Opened File')
        menul.Append(105,'Exit','')
        menuBar.Append(menul,'&File')
        menu2=wx.Menu()
        menuBar.Append(menu2,"&Edit")
        self.SetMenuBar(menuBar)
        wx.EVT_MENU(self,105,self.OnMenuExit)
    def OnToolOpen(self,event):
        self.statusBar.SetStatusText('You open a file')
    def OnMenuExit(self,event):
        self.Close(True)
    def OnCloseMe(self,event):
        self.Close(True)
    def OnCloseWindow(self,event):
        self.Destory()
if __name__=='__main__':
    s=wx.App()
    f=frame(None)
    f.Show()
    s.MainLoop()

遇到的问题

 Traceback (most recent call last):
  File "e.py", line 34, in <module>
    f=frame(None)
  File "e.py", line 8, in __init__
    toolbar.AddSimpleTool(11,wx.Image('C:\Python27\Lib\site-packages\wx\lib\pdfviewer\bitmaps\Save.png',wx.BITMAP_TYPE_PNG).ConvertToBitmap(),"Open","Click it to open a file.")
  File "C:\Python27\lib\site-packages\wx\core.py", line 705, in _Image_ConvertToBitmap
    bmp = wx.Bitmap(self, depth)
wx._core.wxAssertionError: C++ assertion "image.IsOk()" failed at ..\..\src\msw\bitmap.cpp(922) in wxBitmap::CreateFromImage(): invalid image

***Repl Closed***

描述:已经确定bitmaps文件下又Save.png图片

  • 写回答

1条回答 默认 最新

  • m0_37880405 2019-05-13 15:53
    关注

    wx.BITMAP_TYPE_PNG你不要写明图片的类型试一下

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog