Hi,
I need to draw a .png image with transparency on the top of a normal .jpg image. I have looked it up and I have to use wx.PaintDC binded to wx.EVT_PAINT event. The problem is my program needs that “base image .jpg” to be in a sizer so it doens’t fill the entire frame and to show a panel on the left side.
Example of my actual program. That left panel can be showed or hided:
Furthermore, the images needs to have the ability to scale itself and be replaced.
The image with the transparency will be some mascot with a text baloon on top of the base image, which will suposelly help the students how to operate the program.
How can I achieve this?
The only image control which I know of that can be inside a sizer is a wx.StaticBitmap, but when drawn with wx.PaintDC (so it can have transparency), it seems to disrespect the boundaries of the sizer. The image glitches even more when I manually resize the window. Here’s my minimal code so far.
Thank you!
import wx
class Test(wx.Panel):
def __init__(self, parent):
super().__init__(parent)
self.base = wx.StaticBitmap(self, -1)
self.png = wx.StaticBitmap(self.base, -1)
self.base.SetBitmap(wx.Bitmap('base_image.jpg', wx.BITMAP_TYPE_ANY))
self.png.SetBitmap(wx.Bitmap('transparent_image.png', wx.BITMAP_TYPE_PNG))
self.initSizers()
self.Bind(wx.EVT_PAINT, self.OnPaint)
def initSizers(self):
master = wx.BoxSizer(wx.HORIZONTAL)
left = wx.BoxSizer(wx.VERTICAL)
right = wx.BoxSizer(wx.VERTICAL)
left.Add(wx.StaticText(self, -1, 'aaaaaaaaaaaaaa'))
right.Add(self.base)
master.Add(left)
master.Add(right)
self.SetSizer(master)
def OnPaint(self, e):
dc = wx.PaintDC(self)
dc.DrawBitmap(self.base.GetBitmap(), 0, 0, True)
dc.DrawBitmap(self.png.GetBitmap(), 0, 0, True)
class Frame(wx.Frame):
def __init__(self, parent):
super().__init__(parent)
Test(self).Show()
app = wx.App()
Frame(None).Show()
app.MainLoop()