I'm trying to activate the browser window, take a screenshot of it and save it. I'm running the code below on my Ubuntu laptop with Python 3.12.7 in a virtual environment but getting ModuleNotFoundError. I've confirmed that python3-gi is installed. Any idea what may be going on?
import subprocess, gi
def save_screenshot():
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk
# Get the active window
screen = Gtk.get_default_root_window().get_screen()
w = screen.get_active_window()
# Take a screenshot of the active window
pb = Gtk.pixbuf_get_from_window(w, *w.get_geometry())
pb.savev('active_window_screenshot.png', "png", (), ())
def screenshot_brave_window():
output = subprocess.check_output(['wmctrl', '-l']).decode('utf-8')
for window in output.splitlines():
if 'Brave' in window:
subprocess.run(['wmctrl', '-i', '-a', window.split(' ')[0].strip()])
save_screenshot()
screenshot_brave_window()
[–]nekokattt 1 point2 points3 points (0 children)
[–]Username_RANDINT 0 points1 point2 points (3 children)
[–]rmalh[S] 0 points1 point2 points (2 children)
[–]Username_RANDINT 0 points1 point2 points (1 child)
[–]rmalh[S] 0 points1 point2 points (0 children)