pythonuser-interfacewxpythonboxsizer

wx.Python - TypeError: wx.Window, wx.Sizer, Wx.Size, or (w,h) expected


I'm trying to create a wx.Image, and then add it to a wx.BoxSizer and getting a 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 is a string pointing to the path to the 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)

Solution

  • I don't think that wx.Image is a true widget. You will want to put your wx.Image object into a wx.StaticBitmap widget instead. There's a simple tutorial on it here:

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

    Or you might also want to take a look at the wx.Image demo in the wxPython demo (available from the wxPython website).