Hi Mike,
I've been messing around trying to figure out how to make an application
that lets a user choose an image to preview and I cannot get it to work
properly. Ideally, I would allow the user to enter the path to the image
or select it from a FileDialog. The problem isn't with that, however. The
problem is getting the chosen image to display. I started with
wx.StaticBitmap and it works great, if I make the program load an image
BEFORE the application is fully loaded.
If I try to update it with another image of the user's choosing, either
nothing happens or a little black square will appear behind the already
loaded photo. I tried loading an EmptyImage at startup and that worked
too, but updating doesn't work either. I guess I don't know how to set the
control to display a different image. I see there's a Replace() method,
but I don't understand how to use it.
The only workaround I found that kind of works is making a button call and
display a wx.PopupWindow with the image on that. And yes, I checked the
wiki and googled all over. I try to never post without trying diligently
to find the answer on my own.
Currently using Python 2.4, wxPython 2.8.4.2 on Windows XP. Thanks!
I found an old sample I made which works fine and could fit your needs with some adaptation. It's coming at the end of this message.
Also, what could be helpful should be to post a small sample of what you are trying to do. Make it as simple as possible, I'm sure it would be possible to eliminate the problem.
Regards,
jm
import wx
class MainWindow(wx.Frame):
def __init__(self,parent,title):
self.imgList = ['Contacts.png','Contracts.png','Customers.png']
self.imgInd = 0
wx.Frame.__init__(self,parent,wx.ID_ANY,title,style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
self.sizer1 = wx.BoxSizer(wx.VERTICAL)
jpg = wx.Image(self.imgList[self.imgInd],wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.objBmp = wx.StaticBitmap(self,wx.ID_ANY,jpg,size=(128,128),style=wx.SUNKEN_BORDER)
self.sizer1.Add(self.objBmp)
button = wx.Button(self,wx.ID_ANY,'change image')
self.sizer1.Add(button)
button.Bind(wx.EVT_BUTTON,self.OnButton)
self.SetSizer(self.sizer1)
self.Fit()
self.Show(1)
def OnButton(self, event):
self.imgInd += 1
if self.imgInd >= len(self.imgList):
self.imgInd = 0
jpg = wx.Image(self.imgList[self.imgInd],wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.objBmp.Destroy()
self.objBmp= wx.StaticBitmap(self,wx.ID_ANY,jpg,size=(128,128),style=wx.SUNKEN_BORDER)
app = wx.PySimpleApp()
frame=MainWindow(None,'bmp sample')
app.MainLoop()
del app