[Python] Set window icon by glfw in python

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

  1. Stack

    Stack Membro Participativo

    Currently, I using pyGLFW to create a window and I want to set icon for window. I tried to search on the glfw website but it does not support python, and I also tried asking A.I but it encountered an error.

    My current code:

    img = cv2.imread(icon, cv2.IMREAD_UNCHANGED)
    if img is None:
    return False
    h, w = img.shape[:2]
    if img.shape[2] == 3:
    alpha = numpy.ones((h, w, 1), dtype = numpy.uint8) * 255
    img = numpy.concatenate((img, alpha), axis = 2)
    img = img.astype(numpy.uint8)
    img_data = img.flatten()
    glfw_img = (w, h, img_data)
    glfw.set_window_icon(self.window, 1, [glfw_img])


    All libraries I'm using:

    • glfw
    • OpenGL
    • numpy
    • cv2

    Continue reading...

Compartilhe esta Página