2

I know this sounds easy but how can i delete a image with wxpython?

I am using wx.StaticBitmap and wx.Image to create the image, but is there a way to delete an image?

Maybe theres something like this:

bmp1 = wx.Image(filename, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.bitmap1 = wx.StaticBitmap(self.sizer, -1, bmp1, (0, 0))
delete_image(self.bitmap1)
delete_image(bmp1)

I have tried replacing the variable but the image still shows.

1 Answers1

5

self.bitmap1.Hide() or self.bitmap1.Destroy(). The first will just hide it whereas the second will actually destroy the widget. You'll probably want to call self.Layout() to make your window redraw and update the layout of your widgets.

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
  • Do you know if this method will free up the space in the computer memory from previous images? EX: Show Image, Delete Image, Show another Image, Delete Image, Will those images still be in the computer memory? (causing the program to run slower?) –  Nov 09 '11 at 21:20
  • 1
    With Destroy(), the memory occupied by the image will be freed by Python Garbage Collector. –  Nov 09 '11 at 21:46
  • 1
    @dgraziotin is correct, Destroy() will free up memory. Hide() will only hide the widget, so it will stay in memory. This is only helpful if you plan to show the image again and don't want to spend time recreating it. – Mike Driscoll Nov 09 '11 at 22:10
  • And although this isn't really part of the question, if you're looking to hide `bitmap1`, so as to show `bitmap2` (loaded in the same way), it's `self.bitmap2.Show()`. – jmervine Oct 24 '12 at 05:29