0

Web から写真をダウンロードできるプログラムを 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)))
4

1 に答える 1

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上に表示されている回線以外に電話をかけていますか?

于 2013-05-06T09:28:38.257 に答える