Hi
I have made a program with wxPython and i have this bit of code:

def getpic(self,event,urlp='http://mirror.bom.gov.au/radar/IDR043.gif?20080427173538'):
        fc = url.urlretrieve(urlp,filename='Weather.jpg')
        image_file = 'Weather.jpg'
        self.bmp = wx.Bitmap(image_file)
        self.img = wx.StaticBitmap(self.background, wx.ID_ANY, self.bmp, pos = (20, 60))
        self.background.SetInitialSize()

This is a bit of my code, not the full thing but this is the bit that gets an image from the web and plasters it to self.background. My problem is that i want the picture to change so when i give it a url that is different it cleares the current picture from the screen and adds the new image.

Any help would be greatly appreciated. :)

The wx.StaticBitmap() is pretty well static. To be able to clear the old image you best use a canvas to display your image ...

# show a JPEG image using a wx.PaintDC() canvas
# allows you to clear any previous image on the canvas

import wx

class ImagePanel(wx.Panel):
    """ create a panel with a wx.StaticBitmap """
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        # pick an image file you have in the working folder
        # (can be a .jpg, .png, .gif, .bmp image file)
        image_file = 'clouds.jpg'
        self.bmp = wx.Bitmap(image_file)
        # set up a paint event on a PaintDC canvas
        wx.EVT_PAINT(self, self.on_paint)

    def on_paint(self, event=None):
        # create the paint canvas
        dc = wx.PaintDC(self)
        # clear the canvas
        dc.Clear()
        # draw the image
        dc.DrawBitmap(self.bmp, 0, 0, True)


app = wx.App(redirect=False)  # stderr/stdout --> console
# create window/frame
frame = wx.Frame(None, wx.ID_ANY, size = (640, 480))
# create the panel instance
ImagePanel(frame, wx.ID_ANY)
# show the frame
frame.Show(True)
# start the GUI event loop
app.MainLoop()

Hope that helps.

Yeah that works without a hitch.
Thanks vega!

Sorry for unmarking it as solved but i had one more question.

Is there another way apply a bitmap to a panel without making it static?

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.