Last active
October 21, 2024 05:25
-
-
Save KurtJacobson/374c8cb83aee4851d39981b9c7e2c22c to your computer and use it in GitHub Desktop.
Transparent Window in Gtk+ 3, python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Copyright (c) 2017 Kurt Jacobson | |
# License: https://kcj.mit-license.org/@2017 | |
import cairo | |
import gi | |
gi.require_version('Gtk', '3.0') | |
gi.require_version('Gdk', '3.0') | |
from gi.repository import Gtk | |
from gi.repository import Gdk | |
class TransparentWindow(Gtk.Window): | |
def __init__(self): | |
Gtk.Window.__init__(self) | |
self.set_size_request(300, 220) | |
self.connect('destroy', Gtk.main_quit) | |
self.connect('draw', self.draw) | |
screen = self.get_screen() | |
visual = screen.get_rgba_visual() | |
if visual and screen.is_composited(): | |
self.set_visual(visual) | |
self.set_app_paintable(True) | |
self.show_all() | |
def draw(self, widget, context): | |
context.set_source_rgba(0, 0, 0, 0) | |
context.set_operator(cairo.OPERATOR_SOURCE) | |
context.paint() | |
context.set_operator(cairo.OPERATOR_OVER) | |
TransparentWindow() | |
Gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, is there any way to make this not transparent later on?