【发布时间】:2018-02-06 23:20:34
【问题描述】:
我在 Python 2.7 上使用 wxPython。 我需要一些关于创建带有位图图像的按钮的帮助。
我正在使用这个视频https://www.youtube.com/watch?v=Y7f0a7xbWHI, 我按照代码输入了
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Frame aka window',size=(300,200))
panel=wx.Panel(self)
pic=wx.Image("back.bmp", wx.BITMAP_TYPE_BMP).ConvertToBitmap()
self.button=wx.BitmapButton(panel, -1, pic, pos=(10,10))
self.Bind(wx.EVT_BUTTON, self.doMe, self.button)
self.button.SetDefault()
def doMe(self, event):
self.Destroy
创建一个带有图像的按钮。我收到一条错误消息,指出图像无效。 我将位图图像保存在包含我正在使用的 .py 文件的文件夹中。 我觉得我将图像保存在错误的位置? 先感谢您。
我收到的错误
Traceback (most recent call last):
File "C:\Python27\FrameWindow.py", line 81, in <module>
frame=bucky(parent=None,id=-1)
File "C:\Python27\FrameWindow.py", line 17, in __init__
pic=wx.Image("back.bmp", wx.BITMAP_TYPE_BMP).ConvertToBitmap()
File "C:\Python27\lib\site-packages\wx\core.py", line 708, in _Image_ConvertToBitmap
bmp = wx.Bitmap(self, depth)
wxAssertionError: C++ assertion "image.IsOk()" failed at ..\..\src \msw\bitmap.cpp(922) in wxBitmap::CreateFromImage(): invalid image
【问题讨论】:
-
包含您收到的错误非常有帮助,这样其他人可以通过 Google 搜索错误消息并找到它。
-
感谢您告诉我。我是这里的菜鸟。我刚刚添加了错误代码。
标签: python python-2.7 wxpython