如何使 gtk.Window(不是 import Gtk,我的意思是 Gtk.Window)透明?例如对 import gtk, gtk.Window 做同样的事情?
#!/usr/bin/env python
import cairo
from gi.repository import Gtk, Gdk
class MyWin (Gtk.Window):
def __init__(self):
super(MyWin, self).__init__()
self.set_position(Gtk.WindowPosition.CENTER)
self.set_size_request(300, 220)
self.set_border_width(11)
self.screen = self.get_screen()
self.visual = self.screen.get_rgba_visual()
if self.visual != None and self.screen.is_composited():
print "yay"
self.set_visual(self.visual)
self.set_app_paintable(True)
self.connect("draw", self.area_draw)
self.show_all()
def area_draw(self, widget, cr):
cr.set_source_rgba(.2, .2, .2, 0.3)
cr.set_operator(cairo.OPERATOR_SOURCE)
cr.paint()
cr.set_operator(cairo.OPERATOR_OVER)
MyWin()
Gtk.main()