wxpython 控件透明,如何在wxpython中绘制透明框架

UPDATE I completely rephrased the question

I want to create a window with round corners, that's also semi-transparent.

I managed to make a frame semi-transparent by calling the SetTransparent( alpha ) method, however, I still don't know how to make the window have no background.

I tried to get the device context (dc) of the window and set the background brush to wx.TRANSPARENT_BRUSH but that doesn't seem to have any effect.

I'm seeking a kind of effect similar to this for instance, but I want to do it without using a bitmap (i.e. without any external media file).

How do I set the background to nothing?

Update:

it seems what I want is called "shaped window". I'm looking a bit further into that, but still the question is: how can I make one without using any external media file (i.e. purely in code).

解决方案

It's surprising that no one gave an answer ..

Yes, as FogleBird said, it's done with SetShape, but the question is how to get a shape for a ronded rectangle without using an image file.

I found one way to do that, which is to create an empty bitmap and draw on it a rounded rectangle using a memory dc

def GetRoundBitmap( w, h, radius ):

maskColor = wx.Color(0,0,0)

shownColor = wx.Color(5,5,5)

b = wx.EmptyBitmap(w,h)

dc = wx.MemoryDC()

dc.SelectObject(b)

dc.SetBrush(wx.Brush(maskColor))

dc.DrawRectangle(0,0,w,h)

dc.SetBrush(wx.Brush(shownColor))

dc.DrawRoundedRectangle(0,0,w,h,radius)

dc.SelectObject(wx.NullBitmap)

b.SetMaskColour(maskColor)

return b

def GetRoundShape( w, h, r ):

return wx.RegionFromBitmap( GetRoundBitmap(w,h,r) )

One problem I found is that the shape is quiet aliased. Not exactly a nice/fancy window, but better than nothing.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值