Hi guys,

Have been doing some wxPython programming and haven't had any major issues until I wanted to display images! Basically I take readings from an external device (simple input device) and set the image in a panel based on this reading. However it seems that the picture does not change properly. When an event occurs the place where the image was is now grayed out, the only way to get it to display properly is to resize the frame. At this point the image looks fine :S ?

When trying something simple I had a little program that had three buttons. When you clicked a button the image would change. This program worked fine so I don't understand why the images aren't drawn properly in other situations. The code below is used to change a panels image -

class Picture(wx.Panel):
    """ class Panel1 creates a panel with an image on it, inherits wx.Panel """
    def __init__(self, parent, imageFile):
        wx.Panel.__init__(self, parent)
            data = open(imageFile, "rb").read()
            stream = cStringIO.StringIO(data)
            bmp = wx.BitmapFromImage( wx.ImageFromStream( stream ))
            wx.StaticBitmap(self, -1, bmp, (5, 5))
            print imageFile
        except IOError:
            print "Image file %s not found" % imageFile
            raise SystemExit

The following code changes the image (whether it is as a result of external input or a user pressing a button.

def setPicture(self, imageFile):
        self.picturePanel = Picture(self,imageFile)
        self.sizer.Add(self.picturePanel, (3,7),(1,1),2)       

And finally an example of the code being called-


I am at a loss as to why this code seems to work ok when it is called by a button press (event) but not when it is called as a result of external device input! Another issue seems to be that if the image is changed many times the program does not exit properly and hangs! Any help is much appreciated, if I need to provide more information please ask!

Can you try this? Try to bind wx.EVT_IDLE in the main frame or picture frame.

# create the binding to wx.EVT_IDLE
self.Bind(wx.EVT_IDLE, self.OnIdle)

def OnIdle(self, event):

Thank you for your input. After trying this the interface constantly flashes (from the refresh) and when clicking a button to change the image this works better. However the image does not update due to external data unless I change the size of the window :( . It currently takes readings from an accelerometer and is supposed to change the picture to show up to 3 orientations of the device. However you have to resize the GUI for the picture to show when the image is changed in this way.

You can also consider using a wx.Timer widget to update the picture at fixed interval.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.