I need to display a transparent .png image on top of a normal picture. I have tried this aproach, but wxPython says
wxPaintDC can't be created outside wxEVT_PAINT handler
and I can't find a workaround. I binded a wx.EVT_PAINT to some function and tried the code there, with no sucess. Here's my code:
import wx
class Test(wx.Frame):
def __init__(self, parent):
super().__init__(parent)
self.SetTitle('Testing transparency')
self.baseImage = wx.StaticBitmap(self, wx.ID_ANY)
self.DrawBaseImage()
self.DrawOnTop()
def DrawBaseImage(self):
bitmap = wx.Bitmap('path', wx.BITMAP_TYPE_ANY)
image = wx.Bitmap.ConvertToImage(bitmap)
self.baseImage.SetBitmap(image.ConvertToBitmap())
def DrawOnTop(self):
bmp = wx.StaticBitmap(self.baseImage, wx.ID_ANY)
bitmap = wx.Bitmap('path_of_transparent_image', wx.BITMAP_TYPE_PNG)
image = wx.Bitmap.ConvertToImage(bitmap)
bmp.SetBitmap(image.ConvertToBitmap())
app = wx.App()
Test(None).Show()
app.MainLoop()
Thank you!