Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make wxPython, DC background transparent?

How can i make the default white DC background become invisible (transparent)?

Run the following example, it shows a white background over a button. I would like to remove the white background of the DC. (to show only the red 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()
like image 856
thelost Avatar asked Sep 24 '26 13:09

thelost


1 Answers

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

If you are on windows just see above.

If not you basically have to capture the frame below it as an image and paint it (in your onpaint) to fake it

also see http://wxpython-users.1045709.n5.nabble.com/Transparent-Panels-td2303275.html

like image 66
Joran Beasley Avatar answered Sep 27 '26 01:09

Joran Beasley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!