【发布时间】:2021-11-26 05:18:51
【问题描述】:
我需要在普通图片上显示一个透明的 .png 图像。我试过this 方法,但是 wxPython 说
wxPaintDC 不能在 wxEVT_PAINT 处理程序之外创建
我找不到解决方法。我将 wx.EVT_PAINT 绑定到某个函数并在那里尝试了代码,但没有成功。这是我的代码:
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()
谢谢!
【问题讨论】:
标签: image wxpython transparency