Answer the question
In order to leave comments, you need to log in
How to take a screenshot with mouse coordinates using python?
I am using PIL, python 3.3, Win7.
While I do it this way: img = ImageGrab.grab( (x1, y1, x2, y2) )
The question is, how to set the coordinates with the mouse, and not manually write them in the script? Those. when the script was running, the request "Select an area" appeared, I indicate the upper left and lower right corners of the required area, the script takes a screenshot of this part.
And even better, so that you can stretch with the mouse, as if with a frame, select an area. I suspect that you can somehow track the coordinates of pressing the left mouse button, and then the coordinates of its release.
What modules to connect, what to read? Maybe someone will outline an example, I will be grateful.
Answer the question
In order to leave comments, you need to log in
Made poorly (I'm just learning), but it works. I determine the coordinates without clicking, by simply hovering the cursor with a time delay of 3 seconds in order to have time to move the mouse.
from PIL import Image, ImageGrab
import win32api, time
#задаем координаты прямоугольника скриншота
def get_coordinates():
#задаем верхний левый угол
time.sleep(3)
x0, y0=win32api.GetCursorPos()
#задаем правый нижний угол
time.sleep(3)
x_max, y_max=win32api.GetCursorPos()
return(x0,y0,x_max,y_max)
def main():
x0,y0,x_max,y_max=get_coordinates()
img = ImageGrab.grab((x0, y0, x_max, y_max))
img.save(("01.png"), "PNG")
if __name__=='__main__':
main()
stackoverflow.com/questions/1025029/how-to-use-win...
msdn.microsoft.com/en-us/library/ms648390%28VS.85%...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question