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)
getWindowsWithTitle
returns a list , try to access its member
window[0]
and try to extract top
and left
from that