1

我正在尝试制作panel1panel2透明,即背景图像应该是可见的。但这失败了吗?我正在使用panel1.SetTransparent,但它仍然无法正常工作。有人可以建议可能是什么原因。谢谢

import wx
class MainPanel(wx.Panel):
""""""

#----------------------------------------------------------------------
def __init__(self, parent,size):
    """Constructor"""
    wx.Panel.__init__(self, parent=parent,size=size)
    self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
    self.frame = parent

    #sizer = wx.BoxSizer(wx.VERTICAL)
    #hSizer = wx.BoxSizer(wx.HORIZONTAL)


    self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)

#----------------------------------------------------------------------
def OnEraseBackground(self, evt):
    """
    Add a picture to the background
    """
    # yanked from ColourDB.py
    dc = evt.GetDC()

    if not dc:
        dc = wx.ClientDC(self)
        rect = self.GetUpdateRegion().GetBox()
        dc.SetClippingRect(rect)
    dc.Clear()
    bmp = wx.Bitmap("v:/IMAG0081.jpg")
    dc.DrawBitmap(bmp, 0, 0)


  ########################################################################
class MainFrame(wx.Frame):
  """"""

#----------------------------------------------------------------------
def __init__(self):
    """Constructor"""
    wx.Frame.__init__(self, None, size=(600,450))
    panel1 = MainPanel(self,size=(600,450))
    panel2 = wx.Panel(panel1, -1,size=(600,200),style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX)
    panel2.SetTransparent(100)
    panel3 = wx.Panel(panel1, -1,pos=(0,200),size=(600,200),style=wx.BORDER_SUNKEN)
    panel3.SetTransparent(200)
   # panel4 = MainPanel(panel1,size=(600,200))
    #panel2 =MainPanel(panel, -1,size=(600,200),style=wx.BORDER_SUNKEN)

    self.Center()
#
class Main(wx.App):
""""""

#----------------------------------------------------------------------
def __init__(self, redirect=False, filename=None):
    """Constructor"""
    wx.App.__init__(self, redirect, filename)
    dlg = MainFrame()
    dlg.Show()

#----------------------------------------------------------------------  
if __name__ == "__main__":
app = Main()
app.MainLoop()
4

0 回答 0