Python PyGetWindow可以帮助截图吗?
我可以用它来帮助pyautogui截图一个特定的窗口吗?如果是,如何进行?谢谢。是的,您可以为我正在使用的新窗口制作一个特定窗口的屏幕截图,并考虑到在本例中,您要将光标移动到的颜色Python PyGetWindow可以帮助截图吗?,python,automation,pyautogui,Python,Automation,Pyautogui,我可以用它来帮助pyautogui截图一个特定的窗口吗?如果是,如何进行?谢谢。是的,您可以为我正在使用的新窗口制作一个特定窗口的屏幕截图,并考虑到在本例中,您要将光标移动到的颜色 import os import pygetwindow import pyautogui z1 = pygetwindow.getAllTitles() time.sleep(1) # open a file os.startfile("C:\\Users\\name\\path") time
import os
import pygetwindow
import pyautogui
z1 = pygetwindow.getAllTitles()
time.sleep(1)
# open a file
os.startfile("C:\\Users\\name\\path")
time.sleep(1)
z2 = pygetwindow.getAllTitles()
# gets new window title
z3 = [x for x in z2 if x not in z1]
z3 = ''.join(z3)
# activate new window
y = pygetwindow.getWindowsWithTitle(z3)[0]
y.activate()
color_locate = (220,220,220) # edit the color here
locations_of_color = []
s = pyautogui.screenshot()
s.save(r'C:\\Users\\user\\Pictures\\folder\\s.png')
for xx in range(s.width):
for yy in range(s.height):
if s.getpixel((xx, yy)) == color_locate:
located_color = pyautogui.position(xx, yy)
a = [i for i in located_color]
locations_of_color.append(a)
print(len(locations_of_color))
time.sleep(3)
# tries to move to middle
try:
i = len(locations_of_color) // 2
pyautogui.moveTo(locations_of_color[i])
except:
try:
pyautogui.moveTo(locations_of_color[0])
except:
pyautogui.moveTo(locations_of_color)
time.sleep(3)
如果您只需要一个屏幕截图,请使用顶部代码(直到y.activate()),然后执行以下操作:
s = pyautogui.screenshot()
s.save(r'C:\\Users\\user\\Pictures\\folder\\s.png')