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) try: 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.sizer.Remove(self.picturePanel) self.picturePanel.DestroyChildren() self.picturePanel.Destroy() self.picturePanel = Picture(self,imageFile) self.sizer.Add(self.picturePanel, (3,7),(1,1),2) self.SetSizerAndFit(self.sizer) self.Refresh()
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!
Edited 6 Years Ago by jackocurly0074: Incorrect code