High in the previous video, I showed you how to capture a full screen screenshot.
In this video, you'll see how to capture part of the screen via Python.
So this is the codes of the previous video.
For this video, I'm going to create a new file name.
It's partial that p y.
And you need to import from emesis import.
Emesis and tools.
And we use a with context manager, we say with Emma says that Mrs.
We call it.
And so we assign the variable screen to that output.
Then we want to specify the parts of the screen force as a variable, and this should be a dictionary.
So this dictionary has keys and values, so pairs of keys and values.
For example, if you say two fifty seven here, what that means is you're going to store the screenshot
section 257 pixels from the top of the screen.
So somewhere starting from this line and down and then you want to also specify.
Left another key and value, let's say, 900, so that means 900 pixels from the left of the screen.
So we have one line here and one line here.
That means this part of the screen here will be captured.
But then we can also specify a width as a string, of course, width.
So how many pixels do you want to go from this border up to here?
Let's say we want to go about 500 pixels, so that would be 500 as the width and the height would be
perhaps 400.
So the height of the from this, from this line, four hundred pixels down.
So more or less, we're capturing perhaps this area in here.
So once we have that dictionary, then we can use the screen dots grab.
Methods, so previously we used the screen, but shot methods for part of the screen we use, grab and
grab now gets these part as arguments.
And this methods will return that image and then we see tools that's p to P and G.
So that's a methods.
And then you want to specify the image, which we get from GRAP, but we want the argy bargy property,
which will give us the image in bytes in colour.
So that will give us the actual image file in bytes.
You also want to specify image size, which you can get from image that size.
So that's the size argument, that's the actual image.
So what size do you want to produce it?
And finally, the outputs is equal to the path.
What he wants to save that image, such as output, that's p and G, and we are ready to run this school.
So.
Right click wrong partial and serious output at PG.
That's the screen shot area.
So depending on your screen, how big your screen is, you could capture different areas of the screen.
So for me, it captured the area somewhere in here.
I can try again by putting this text here and running again.
And see Ultimates this time.
So you see, it's to the left or the right key here, so it's somewhere in here of the area.
My screen resolution currently is 1920 horizontally and.
Ten eighty vertically.
So one, nine, nine hundred is somewhere in the middle, yeah, somewhere in here.
900 pixels from the left and 250 from the upper corner.
So we get this area.
Now, if you want to know how to get the position of the cursor, so if you want to capture this area
and you want to know what pixel that points is, then you can use PI all to gooey a third party library,
which I'll use in the next videos.
It allows you to control the cursor the moors so you can know what position of the cursor is currently
python with.
Tell you that.
And then you can instruct Python to move the cursor on the screen where you want it to be and to do
clicks and drags.
You can draw on canvas if you have a sketch application where you can draw things around and you can
click file, scanned, copy, text and paste it.
So you can do all of that via Python, and I'll teach you how to do that in the next videos.
So I'll see you there.