It is possible to make the whole frame transparent using
SetTransparent(val) in wxpython. But can I make a single panel in it to be transparent?
I tried using
panelobj.SetTransparent(val) but that didnt work.
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title,size=(250, 250))
topPanel = wx.Panel(self)
panel1 = wx.Panel(topPanel, -1)
panel2 = wx.Panel(topPanel, -1)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(panel1,1,flag = wx.EXPAND|wx.ALL)
sizer.Add(panel2,1,flag = wx.EXPAND|wx.ALL)
frame = MyFrame(None, -1, 'frame')
app = MyApp(0)
supposing I want to set transparency for panel1.
Best How To :
It's platform-specific which windows can and can't be made transparent.
CanSetTransparent method allows you to check whether a window's transparency can be toggled at runtime. If it returns false,
SetTransparent will (usually) do nothing, and you shouldn't call it.
Off the top of my head (but don't quote me on this—it must be documented somewhere, but I can't find it…):
- Mac OS X with Cocoa build: anything can be transparent.
- Mac OS X with Carbon build (which nobody uses anymore): only top-level windows can be transparent.
- Windows: only top-level windows can be transparent.
- X11 with compositor: anything can be transparent.
- X11 without compositor: nothing can be transparent.
- Wayland (which is still experimental): anything can be transparent.
However, Windows is a special case. While you can't toggle a sub-window's transparency, or set it to a percentage, you can make it fully transparent at creation time, as shown in ρss's answer.
So, if that's what you're looking for, and you want to do it as portably as possible, you'll want something like this:
style = wx.TRANSPARENT_WINDOW if sys.platform.lower() == 'win32' else 0
panel1 = wx.Panel(topPanel, -1, style=style)