如何使用 PyGTK 和 PyCairo 在窗口中获得透明背景?
我一直在努力使用 PyGTK 创建一个没有装饰和透明背景的窗口。然后我会用 Cairo 绘制窗口的内容。但我无法让它发挥作用。
我尝试了很多不同的方法,但都失败了,这就是其中之一
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk, sys, cairo
win = None
def expose (widget, event):
cr = widget.window.cairo_create()
#Start drawing
cr.set_operator(cairo.OPERATOR_CLEAR)
cr.set_source_rgba(0.5,1.0,0.0,0.5)
cr.rectangle(0, 0, 0.9, 0.8)
cr.fill()
def main (argc):
global win
win = gtk.Window()
win.set_decorated(False)
win.connect('delete_event', gtk.main_quit)
win.connect('expose-event', expose)
win.set_app_paintable(True)
win.show()
gtk.main()
if __name__ == '__main__':
sys.exit(main(sys.argv))
那么,最简单的方法是什么?
I've been trying really hard to create a window with no decoration and a transparent background using PyGTK. I would then draw the content of the window with Cairo. But I can't get it to work.
I've tried a lot of different ways, they all failed, this is one of them
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk, sys, cairo
win = None
def expose (widget, event):
cr = widget.window.cairo_create()
#Start drawing
cr.set_operator(cairo.OPERATOR_CLEAR)
cr.set_source_rgba(0.5,1.0,0.0,0.5)
cr.rectangle(0, 0, 0.9, 0.8)
cr.fill()
def main (argc):
global win
win = gtk.Window()
win.set_decorated(False)
win.connect('delete_event', gtk.main_quit)
win.connect('expose-event', expose)
win.set_app_paintable(True)
win.show()
gtk.main()
if __name__ == '__main__':
sys.exit(main(sys.argv))
So, what is the simplest way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以,我实际上自己解决了这个问题。
这是一个工作示例。我已经评论了相关部分,以防其他人对如何执行此操作感兴趣。
So, I actually figured this out myself.
This is a working example. I've commented the relevant parts just in case somebody else is interested in how to do this.
确切的问题已在论坛中得到解决。但它是在 C++ 中。尝试去理解这一点。
按照这个:
Linux 问题
请参阅 phorgan1 发表的评论。
希望这有帮助......
The exact problem has been addressed in a forum . But it is in C++ . Try to understand that .
Follow this :
Linux Questions
See the comment posted by phorgan1 .
Hope this helps....