Transparent frame background

How can I make a frame with a transparent background? I want to be
able to draw stuff on the frame, but have the desktop show through
where I haven't drawn anything.

Try calling the frame’s SetTransparent() method. There’s a silly example here: http://www.blog.pythonlibrary.org/2008/04/14/doing-a-fade-in-with-wxpython/

···

Mike Driscoll

Blog: http://blog.pythonlibrary.org

No, that makes all of it’s children transparent too. I’m don’t want a transparent frame, I want a transparent frame background.

···

On Mon, Aug 1, 2011 at 13:08, Mike Driscoll kyosohma@gmail.com wrote:

Try calling the frame’s SetTransparent() method. There’s a silly example here: http://www.blog.pythonlibrary.org/2008/04/14/doing-a-fade-in-with-wxpython/


Mike Driscoll

Blog: http://blog.pythonlibrary.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

You want to do the exact opposite of what the attached demo does: - Create a mask bitmap for the Frame decorations: title bar and the surrounding border. This is every other part of the Frame that is not the Frame’s Client area.

The harder part is how to determine the position (the origin) of the client area relative to the Frame (0, 0). One way would be to place a Panel inside the Frame. Then, find the positions of Panel in absolute desktop coordinates by using ClientToScreen(). The position of the Frame is already given in the desktop coordinate system. The delta offset between the 2 coordinates is what you want.

Make a new bitmap the size of the Frame to be used as the transparency mask. Define 2 colors - the exact color values are completely unimportant. dc.Clear() the entire bitmap with the color that will not become transparent using [ dc.SetBrush() ]. Use [ dc.DrawRectangle() ] to paint the area that represents the Client area that will become transparent using the other. Remember to set the Frame’s transparency amount.

Ray Pasco

FRAME-BORDERLESS-SHAPED-TRANSPARENT.PY (3.38 KB)

I stand corrected: When using the style wx.FRAME_SHAPED all Frame decorations can’t exist. Only the Client area remains to manipulate with transparency. There doesn’t seem to be an easy way to accomplish this, probably because it’s rarely wanted.

  1. You could create your own title bar with buttons to recreate what the standard title bar does.

  2. Two frames could be created that are positionally “synced” to each other. The first would be a normal Frame whose Client area vertical size is 0. This gives you all the buttons.

The second frame is wx.FRAME_SHAPED. Handling wx.EVT_MOVE on the on the top visible Frame gives the position location of the bottom edge in which the lower invisible Frame is to aligned exactly underneath. If you need the west, south and east side borders in the lower Frame you could create a PNG file of these and display this bitmap into the lower Frame using a mask bitmap derived from the border bitmap itself. This “border” wouldn’t normally be functional since its just a bitmap, not a real border control. The rest of this Frame’s interior is made transparent.

This method is a kludge, but it should work well enough. It can’t easily be resized, but I don’t know if this is a requirement. You also haven’t stated the purpose of the invisible Client interior.

···

On Mon, Aug 1, 2011 at 7:53 PM, Ray Pasco pascor22234@gmail.com wrote:

You want to do the exact opposite of what the attached demo does …


Ray Pasco

Take a look at the attached demo. It uses all of the trickiest techniques I’ve described in my previous post. In the IMAGES folder the image files names in CamelCase I created in PhotoShop. You could use The Gimp, instead. The filenames in upper case are generated by the app simply to show you what needed bitmaps are generated internally by the app.

Since both the always-visible outer Frame and the inner Frame with less than 100% opaqueness are created much in the same way the argument [ outer_or_inner_window ] is given as 0 or non-zero to signify which Frame is being instantiated in the 2 separate calls. You best create 2 separate classes for clearer program organization.

Ray Pasco

CustomShapeFrame_Demo.zip.remove_this_extension (428 KB)