Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

pygetwindow Error, AttributeError: 'list' object has no attribute 'topleft'

I am trying to get a screenshot of a specific window, but I get the following Error: AttributeError: ‘list’ object has no attribute ‘topleft’. How can I solve it ?

import pygetwindow
import pyautogui
from PIL import Image
import platform

path = 'report/result.png'
titles = pygetwindow .getAllTitles()

if platform.system() == 'Windows':
    window = pygetwindow.getWindowsWithTitle('bachelor-project-vision-based-traffic-scene-surveillance – report.py')
    #print(titles)
    left, top = window.topleft
    right, bottom = window.bottomright
    pyautogui.screenshot(path)
    im = Image.open(path)
    im = im.crop((left, top, right, bottom))
    im = im.save(path)
    im.show(path)

elif platform.system() == 'Darwin':
    x1, y1, width, height = pygetwindow .getWindowGeometry('Chrome')
    x2 = x1 + width
    y2 = y1 + height
    pyautogui.screenshot(path)
    im = Image.open(path)
    # im = im.crop((x1, y1, x2, y2+10))
    im.save(path)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

getWindowsWithTitle returns a list , try to access its member

window[0] and try to extract top and left from that

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading