在 wxPython 中创建异形窗口的最简单方法是什么?
我想在 wxPython 中创建一个简单形状的窗口。或多或少我想做相当于 Tkinter 的 self.overrideredirect(1) 的 wx (它摆脱了默认的操作系统边框),然后圆化窗口的角。
I'd like to create a simple shaped window in wxPython. More or less I want to do the wx equivalent to Tkinter's self.overrideredirect(1) (It get's rid of the default OS boarder), then round the corners on the window.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
wxPython 演示中有一个异形框架演示。我对间接来源表示歉意。它们最初作为 Windows 安装程序 此处:
源代码
您需要查看 Shaped_frame_mobile。 py 或 Shaped_frame.py,它们都从示例窗口位图的列表中调用 images.py。它并不完全等同于overrideredirect,因为您必须提供要为框架绘制的图像,但它仍然可以帮助您完成类似的任务。
重要的部分是基于位图设置窗口形状并处理 wx.EVT_PAINT 事件的函数:
编辑 - 这是一个更改的
shape_frame_mobile.py
,它加载 IMAGE_PATH 变量中指定的 .png 图像。将其更改为指向您的图像:There's a shaped frame demo in the wxPython demos. I apologize for the indirect source. They originally came as a windows installer here:
source code
You'll want to look at shaped_frame_mobile.py or shaped_frame.py, which both call images.py from that listing for the sample window bitmap. It's not the exact equivalent to
overrideredirect
since you will have to provide an image to be drawn for the frame, but it could still help you accomplish something similar.The important parts are the functions that set the window shape based on the bitmap and handle the wx.EVT_PAINT event:
Edit - Here's an altered
shaped_frame_mobile.py
that loads the .png image specified in the IMAGE_PATH variable. Change that to point to your image:伙计们,我知道有一个公认的答案,我在 ubuntu 和 python 2.x 中使用了该答案,但是当我尝试在 windows python 3.x 上使用它时,它不起作用。所以我经过小研究后修复了它(wx.Region需要透明颜色,请参见下面的代码)。并改变了几个折旧方法:
Guys I know there is a accepted answer, I used that answer in ubuntu with python 2.x, however when I tried to use it on windows python 3.x it didn't work. So I fixed it after small research (wx.Region needs a transparent color, see below code). And changed several depreciated methods: