如何使wxPython,DC背景透明?

时间:2012-03-16 01:20:22

标签: c++ python wxpython wxwidgets

如何使默认的白色DC背景变得不可见(透明)?

运行以下示例,它在按钮上显示白色背景。我想删除DC的白色背景。 (仅显示红色X)

import wx


class drawover(wx.Window):
    def __init__(self, parent):
        wx.Window.__init__(self, parent)


        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnErase)
        self.Bind(wx.EVT_SET_FOCUS, self.OnFocus)


    def OnFocus(self, evt):
        self.GetParent().SetFocus()


    def OnErase(self, evt):
        pass


    def OnPaint(self, evt):
        dc = wx.PaintDC(self)
        dc.BeginDrawing()
        dc.SetPen(wx.Pen("RED", 1))
        dc.DrawLineList([(0,0,100,100), (100,0,0,100)])
        dc.EndDrawing()


class frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, size=(600,600))


        s = wx.BoxSizer(wx.VERTICAL)


        self.tc1 = wx.TextCtrl(self, style=wx.TE_MULTILINE)
        s.Add(self.tc1, 1, wx.EXPAND)
        self.tc2 = wx.Button(self)
        s.Add(self.tc2, 1, wx.EXPAND)


        self.d = drawover(self.tc2)


        self.tc2.Bind(wx.EVT_SIZE, self.OnSize2)


        self.SetSizer(s)
        self.Layout()


    def OnSize2(self, evt):
        self.d.SetSize((101,101))


if __name__ == '__main__':
    a = wx.App(0)
    b = frame()
    b.Show(1)
    a.MainLoop()

1 个答案:

答案 0 :(得分:2)

http://wiki.wxpython.org/Transparent%20Frames

如果你在窗户上,请看上面。

如果不是,你基本上必须将其下方的帧捕获为图像并将其绘制(在你的onpaint中)以伪造它

也看到了 http://wxpython-users.1045709.n5.nabble.com/Transparent-Panels-td2303275.html