1
00:00:01,680 --> 00:00:08,670
OK, so we've installed an imported pillow and pill and actually let's take this guy needs to actually

2
00:00:08,670 --> 00:00:17,220
be below here, so, OK, looking through this, OK, so now let's write the code to actually save our

3
00:00:17,220 --> 00:00:17,510
image.

4
00:00:17,520 --> 00:00:19,330
So I'm in our save as PNG function.

5
00:00:19,540 --> 00:00:21,840
Now, the first thing we need to do is create an if statement.

6
00:00:21,840 --> 00:00:23,040
So let's go if result.

7
00:00:23,310 --> 00:00:30,000
So basically we can run our little file dialog thing and then click, cancel and actually not type in

8
00:00:30,000 --> 00:00:33,000
anything, you know, don't type in Bob, not PNG or whatever.

9
00:00:33,270 --> 00:00:35,650
And if that's the case, there won't be a result.

10
00:00:35,670 --> 00:00:40,230
So we need to make sure that doesn't happen or that hasn't happened because otherwise we would try to

11
00:00:40,230 --> 00:00:41,940
save the file without a file name.

12
00:00:41,940 --> 00:00:42,600
And that's no good.

13
00:00:42,610 --> 00:00:46,390
So only if there's a file name, then let's run this code.

14
00:00:46,560 --> 00:00:50,130
I'm just going to paste in some code here and let's take a look at this.

15
00:00:50,130 --> 00:00:51,520
So we need some coordinates, right.

16
00:00:51,540 --> 00:00:55,880
So what we're trying to do is we need to get the X and Y coordinates for our root window.

17
00:00:56,070 --> 00:01:00,090
We need to get the X and Y coordinates for the canvas itself.

18
00:01:00,210 --> 00:01:05,730
And we need the height in the width of the actual program so we can sort of.

19
00:01:06,730 --> 00:01:11,740
Compare all those coordinates and only save what we want to save, because remember, we're just saving

20
00:01:12,040 --> 00:01:14,680
the canvas itself, we're dropping out everything else.

21
00:01:14,710 --> 00:01:23,160
So what we're doing here is we're calling these WFA Route X and Y and this W info underscore X and info

22
00:01:23,230 --> 00:01:24,070
underscore Y.

23
00:01:24,160 --> 00:01:27,010
And these are just things that grab information about our widget.

24
00:01:27,010 --> 00:01:34,150
So we're grabbing the info for the canvas and the Y info for the canvas and the root X window for our

25
00:01:34,150 --> 00:01:39,110
root window and Y coordinates for our root root window here as well.

26
00:01:39,400 --> 00:01:48,150
So then we're going to add those to our height and width of the actual canvas itself.

27
00:01:48,160 --> 00:01:48,500
Right.

28
00:01:50,480 --> 00:01:53,870
Don't think too hard on this, this is just how this works, right?

29
00:01:54,050 --> 00:01:58,760
So now we're going to image grab and that is from this image grab right here.

30
00:01:58,790 --> 00:02:00,550
We just imported from Pelo, right.

31
00:02:00,890 --> 00:02:02,040
And what are we going to do with it?

32
00:02:02,060 --> 00:02:04,550
We're going to grab and then we're going to crop out.

33
00:02:04,790 --> 00:02:09,530
And here's where we pass in our coordinates and make sure to put these in double brackets here.

34
00:02:09,830 --> 00:02:11,320
Don't miss that little part there.

35
00:02:11,330 --> 00:02:12,820
So then we want to save it.

36
00:02:12,860 --> 00:02:14,090
What do we want to save it as?

37
00:02:14,090 --> 00:02:17,380
We want to save it as a result, which is what we've we've called this thing.

38
00:02:17,390 --> 00:02:20,870
So, again, don't overthink all this code.

39
00:02:20,870 --> 00:02:25,610
This is just we're grabbing the coordinates for X in our wise four hour window on our our canvass,

40
00:02:25,610 --> 00:02:29,810
and then we're cropping out the stuff we don't want and saving the stuff that we do want.

41
00:02:29,840 --> 00:02:31,250
So let's go and save this.

42
00:02:31,430 --> 00:02:32,510
And let's run this.

43
00:02:36,150 --> 00:02:45,840
And let's draw I don't know, let's draw a nice little mountain and let's see what else do we need?

44
00:02:45,960 --> 00:02:46,590
A sun.

45
00:02:49,210 --> 00:02:52,480
There you go, and this needs.

46
00:02:53,420 --> 00:02:55,550
So, Sunrays.

47
00:03:01,230 --> 00:03:05,940
I am terrible, this endless change, the color we need some blue skies.

48
00:03:09,120 --> 00:03:10,050
Some light blue.

49
00:03:10,880 --> 00:03:16,320
All right, and what else, we need some trees, right?

50
00:03:20,340 --> 00:03:22,230
Green trees, man, that's bad.

51
00:03:23,970 --> 00:03:28,020
Don't laugh at me, I'm bad at drawing, OK, so good enough.

52
00:03:28,020 --> 00:03:29,310
Let's go ahead and save this.

53
00:03:32,040 --> 00:03:38,340
Analysts say this is mountain and we don't have to put PNG because we wrote some code otherwise, and

54
00:03:38,340 --> 00:03:43,640
now we can bring up this mountain, this file thing here and here, we see mountain top PNG.

55
00:03:43,650 --> 00:03:46,230
And if we don't click this boom, here is our image.

56
00:03:47,050 --> 00:03:49,080
It's bad, but it pretty much works now.

57
00:03:49,350 --> 00:03:55,830
This is pretty good, except except when we did this and we clicked the button, we really need something

58
00:03:55,830 --> 00:03:59,840
to pop up and say, hey, that was saved successfully.

59
00:03:59,850 --> 00:04:00,180
Right.

60
00:04:00,420 --> 00:04:02,430
So we'll go ahead and look at that in the next video.
