Change control(Image) in Box sizer

Hi,

I have a BoxSizer holding an Image.

    def __init__(self, parent, ID):
        wxPanel.__init__(self, parent, -1)

        box = wxBoxSizer(wxVERTICAL)
        gif = wxImage(opj('images/test.gif'),
wxBITMAP_TYPE_GIF).ConvertToBitmap()
        self.img = wxStaticBitmap(self, -1, gif, wxPoint(0, 0),
                                  wxSize(gif.GetWidth(),
gif.GetHeight()))
        box.Add(self.img, 0, wxALIGN_TOP)

  box.Add(wxButton(.....

Now I want to change the Image in the upper position:

    def LoadBitmap(self, filename):

        gif = wxImage(opj(filename),
wxBITMAP_TYPE_GIF).ConvertToBitmap()
        self.img1 = wxStaticBitmap(self, -1, gif, wxPoint(0, 0),
                                  wxSize(gif.GetWidth(),
gif.GetHeight()))

        self.GetSizer().Remove(self.img)
        self.GetSizer().Add(self.img1, 0, wxALIGN_TOP)
        self.GetSizer().Layout()

The old Bitmap disappears from the top and the control under it moves
to the top but rests of the old image rest under it and the new image
is displayed at the bottom, but I want to have it on TOP.

Someone knows a solution? Thanks,

Markus

Markus von Ehr wrote:

Now I want to change the Image in the upper position:

    def LoadBitmap(self, filename):

        gif = wxImage(opj(filename),
wxBITMAP_TYPE_GIF).ConvertToBitmap()
        self.img1 = wxStaticBitmap(self, -1, gif, wxPoint(0, 0),
                                  wxSize(gif.GetWidth(),
gif.GetHeight()))

        self.GetSizer().Remove(self.img)
        self.GetSizer().Add(self.img1, 0, wxALIGN_TOP)
        self.GetSizer().Layout()

The old Bitmap disappears from the top and the control under it moves
to the top but rests of the old image rest under it and the new image
is displayed at the bottom, but I want to have it on TOP.

Someone knows a solution?

First of all, removing an item from the sizer does not remove it from the window. The wxStaticBitmap still eixists and is shown. To really remove it you should at least Hide() it or maybe Destroy() it if you are really finished with it.

Secondly, if you just want to change the image shown then you can just give the wxStaticBitmap a new image to display using self.img.SetBitmap(gif).

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!