wx.Python - TypeError:wx.Window,wx.Sizer,Wx.Size或(w,h)预期

时间:2013-06-03 00:26:41

标签: python user-interface wxpython boxsizer

我正在尝试创建一个wx.Image,然后将其添加到wx.BoxSizer并获取TypeError

Traceback (most recent call last):
  File "gui.py", line 72, in <module>
    frame = CardFrame(None, cards[0])
  File "gui.py", line 45, in __init__
    imgSizer.Add(imgImage, 0, wx.ALL)
  File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 12697, in Add
    return _core_.Sizer_Add(*args, **kwargs)
TypeError: wx.Window, wx.Sizer, wx.Size, or (w,h) expected for item

image是一个指向图像路径的字符串(〜/ app / static / imgs / grizzly_bear.png)

image = os.path.join(IMGS, card.img)
bkg = wx.Panel(self)
#...
imgSizer = wx.BoxSizer(wx.HORIZONTAL)
imgSizer.SetMinSize((240, 120))
#...
imgImage = wx.Image(image, wx.BITMAP_TYPE_ANY)
#...
imgSizer.Add(imgImage, 0, wx.ALL)
#...
topSizer.AddMany(imgSizer, 0, wx.ALL)

1 个答案:

答案 0 :(得分:1)

我不认为wx.Image是一个真正的小部件。您将希望将wx.Image对象放入wx.StaticBitmap小部件中。这里有一个简单的教程:

http://www.blog.pythonlibrary.org/2010/03/26/creating-a-simple-photo-viewer-with-wxpython/

或者您可能还想查看wxPython演示中的wx.Image演示(可从wxPython网站获得)。