[Python] How do I get icon of window as PNG using python xlib?

Discussão em 'Python' iniciado por Stack, Junho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I am working on a window manager made in Python 3 using python-xlib. When I tried to implement displaying the icons (as a PNG) on a window as a 16x16 image, it worked with this dummy image, but when I tried to actually get the window's icon, it returned None.

    from Xlib.display import Display
    from Xlib import X
    from PIL import Image

    def getIcon(window, display):
    icon_data = window.get_full_property(
    display.intern_atom('_NET_WM_ICON'),
    X.AnyPropertyType
    ).value

    width = icon_data[0]
    height = icon_data[1]

    image = Image.frombytes(
    'RGBA', (width, height), bytes(icon_data[2:]), 'raw', 'BGRA'
    )
    return image

    Continue reading...

Compartilhe esta Página