问题描述
更新我完全改掉了这个问题
UPDATE I completely rephrased the question
我想创建一个带有圆角的窗口,该窗口也是半透明的.
I want to create a window with round corners, that's also semi-transparent.
我通过调用SetTransparent( alpha )
方法设法使框架半透明,但是,我仍然不知道如何使窗口没有背景.
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.
我试图获取窗口的设备上下文(dc),并将背景笔刷设置为wx.TRANSPARENT_BRUSH
,但这似乎没有任何作用.
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).
如何将背景设置为空?
似乎我想要的是成形窗口".我正在进一步研究那个,但问题仍然是:如何在不使用任何外部媒体文件的情况下制作一个(即纯粹在代码中).
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 ..
是的,正如FogleBird所说的,它是用SetShape
完成的,但是问题是如何在不使用图像文件的情况下获得圆形矩形的形状.
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.
我找到了一种方法,那就是创建一个空的位图并使用内存dc在其上绘制一个圆角矩形
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.
这篇关于如何在wxpython中绘制透明框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!