import gi gi.require_version('Gdk', '3.0') from gi.repository import Gdk # Get the default window and create a screenshot window = Gdk.get_default_root_window() screenshot = Gdk.pixbuf_get_from_window(window, *window.get_geometry()) # Save the screenshot to a file screenshot.savev("screenshot.png", "png", [], [])
import gi gi.require_version('Gdk', '3.0') from gi.repository import Gdk # Get the default window and create a GC (graphics context) window = Gdk.get_default_root_window() gc = Gdk.cairo_create(window) # Draw a rectangle on the screen gc.set_source_rgb(1, 0, 0) # Set the color to red gc.rectangle(100, 100, 200, 200) # Draw a rectangle gc.stroke() # Stroke the rectangle (draw the outline)This code draws a red rectangle on the default window using GDK's Cairo drawing context. Overall, the Gdk library is a package library for handling graphics in GTK+ applications. It provides a range of functions and classes for working with graphics, including capturing screenshots and drawing on the screen.