我在python中编写了一个可以从网上下载图片的程序。 对于每个下载的图片,它都在GUI中预览该图片,但每次都这样做我收到以下错误:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 14665, in <lambda>
lambda event: event.callable(*event.args, **event.kw) )
TypeError: 'NoneType' object is not callable
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 14665, in <lambda>
lambda event: event.callable(*event.args, **event.kw) )
TypeError: 'NoneType' object is not callable
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 14665, in <lambda>
lambda event: event.callable(*event.args, **event.kw) )
TypeError: 'NoneType' object is not callable
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 14665, in <lambda>
lambda event: event.callable(*event.args, **event.kw) )
TypeError: 'NoneType' object is not callable
有趣的是:它仍然有效。但这个错误意味着什么?我该如何解决?
导致此错误的代码应为以下行:
wx.CallAfter(self.image.SetBitmap, wx.BitmapFromImage(wx.Image(imagePath, wx.BITMAP_TYPE_ANY).Rescale(width, height)))
答案 0 :(得分:0)
我无法使用以下代码重现您的问题:
#!/usr/bin/env python
import wx
class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Title")
panel = wx.Panel(self)
box = wx.BoxSizer(wx.VERTICAL)
button = wx.Button(panel, wx.ID_ANY, "Load image")
button.Bind(wx.EVT_BUTTON, self.ChangeImage)
box.Add(button, 0, wx.ALL, 10)
self.image = wx.StaticBitmap(panel)
box.Add(self.image, 0, wx.ALL, 10)
panel.SetSizer(box)
panel.Layout()
def ChangeImage(self, event):
wx.CallAfter(self.image.SetBitmap, wx.BitmapFromImage(wx.Image("modernart.png", wx.BITMAP_TYPE_ANY).Rescale(150, 150)))
if __name__ == "__main__":
app = wx.App()
top = Frame()
top.Show()
app.MainLoop()
(您需要在同一文件夹中显示modernart.png
图片。我会留待您创建。)
如果我使用self.image.setBitmap
将wx.CallAfter
替换为None
,那么我就可以重现您的错误。
您是否在上面显示的行以外的地方呼叫wx.CallAfter
?