1
00:00:01,580 --> 00:00:05,450
OK, in this video, I want to show you how to use images in your new windows because there's a little

2
00:00:05,450 --> 00:00:06,190
bit of a trick to it.

3
00:00:06,200 --> 00:00:14,840
So first, we need to come back up to the top here and re-import from Hill import image, Teekay and

4
00:00:14,840 --> 00:00:15,460
Image.

5
00:00:15,770 --> 00:00:20,210
We looked at this, you know, a few videos ago and we looked at using images.

6
00:00:20,510 --> 00:00:21,560
I just removed it.

7
00:00:21,570 --> 00:00:22,930
I'm still in my new tappy file.

8
00:00:22,940 --> 00:00:29,450
So now let's come down here to our new window here and just below that label, which we don't really

9
00:00:29,450 --> 00:00:29,930
need.

10
00:00:31,540 --> 00:00:33,430
Let's create an image real quick.

11
00:00:33,460 --> 00:00:42,240
So remember, let's just call my image and this is a image, Teekay Dot photo image.

12
00:00:42,610 --> 00:00:47,700
And so then we want to go image dot open and inside of this, what did we want?

13
00:00:47,710 --> 00:00:52,300
We want this to be Aspen, Dot, P and G.

14
00:00:52,300 --> 00:00:53,530
I think it was PMG.

15
00:00:53,550 --> 00:00:57,430
Let me check and make sure Elst list the stuff.

16
00:00:57,430 --> 00:00:57,600
Yeah.

17
00:00:57,610 --> 00:00:58,850
Aspen dot PMG.

18
00:00:59,360 --> 00:01:06,580
OK, now we can create a label, let's go img label and that's a label.

19
00:01:07,330 --> 00:01:11,110
And we want this to be in new because we're working in our new window.

20
00:01:11,110 --> 00:01:11,460
Right.

21
00:01:12,010 --> 00:01:16,060
And we want the image to equal my equal.

22
00:01:17,630 --> 00:01:22,970
I underscore img finally, let's go img label dot pack.

23
00:01:24,610 --> 00:01:31,060
And let's give this up pad, why, of five or so, just to smash it down a little bit and let's give

24
00:01:31,060 --> 00:01:36,160
this next button also a pad, why just smash it down a little bit?

25
00:01:36,970 --> 00:01:41,680
OK, and before we run this, let's change this to four hundred by four hundred two.

26
00:01:41,690 --> 00:01:43,070
So this image shows up.

27
00:01:43,090 --> 00:01:44,350
So let's say this.

28
00:01:44,860 --> 00:01:46,500
Come over here and run it.

29
00:01:47,110 --> 00:01:48,490
So here we have our first one.

30
00:01:48,490 --> 00:01:49,300
No boom.

31
00:01:50,050 --> 00:01:53,290
Here we have our second window and it's still not quite all showing up.

32
00:01:53,290 --> 00:01:54,920
We might have to make this a little bigger still.

33
00:01:55,390 --> 00:01:55,680
All right.

34
00:01:55,690 --> 00:01:56,890
So that seems to work, right?

35
00:01:57,730 --> 00:02:03,180
So let's come back up here and make this five hundred by seven hundred.

36
00:02:03,700 --> 00:02:04,480
Now, that works.

37
00:02:04,480 --> 00:02:07,330
But OK, let's say you forgot your new lube thing.

38
00:02:07,330 --> 00:02:12,250
Remember I said sometimes I forget this main loop thing when we created our second window.

39
00:02:12,250 --> 00:02:14,110
So we save this now and run it.

40
00:02:15,920 --> 00:02:16,760
Again.

41
00:02:21,060 --> 00:02:27,390
Open the second window and, oh, now the the image doesn't show up, so as long as you remember to

42
00:02:27,390 --> 00:02:29,520
run your main loop, everything's fine.

43
00:02:29,850 --> 00:02:35,340
But if you don't, then what's happening here is let's look back at our code.

44
00:02:35,700 --> 00:02:40,530
When we first created our program here at the bottom, we created this main loop, and that's the main

45
00:02:40,530 --> 00:02:40,980
loop.

46
00:02:41,220 --> 00:02:48,390
And as it's looking and spinning and looping and doing things, it doesn't know what this image is inside

47
00:02:48,390 --> 00:02:52,680
of this inside of this function, because it's a new window.

48
00:02:52,680 --> 00:02:57,060
It's a new function that gets confused and has something to do with garbage collection that I don't

49
00:02:57,060 --> 00:02:57,930
really want to get into.

50
00:02:58,320 --> 00:02:59,610
But it just gets confused.

51
00:02:59,620 --> 00:03:00,750
So what you can do here.

52
00:03:00,960 --> 00:03:05,520
So this is kind of a hack you can do here if you grab this very first variable.

53
00:03:05,970 --> 00:03:06,300
Right.

54
00:03:06,450 --> 00:03:08,680
This is where we defined our image.

55
00:03:09,120 --> 00:03:13,750
This is a local variable, which means it works inside of this function.

56
00:03:14,100 --> 00:03:17,270
Well, our main loop is outside of that function.

57
00:03:17,280 --> 00:03:19,760
It's looping around and spinning around is doing its thing.

58
00:03:20,010 --> 00:03:26,280
It doesn't know what this variable, where to go, what this variable is, because it's a local variable.

59
00:03:26,550 --> 00:03:32,010
And so it can't figure out what to display, has something to do with the garbage function of Quinter.

60
00:03:32,010 --> 00:03:33,320
We won't get into any of that.

61
00:03:33,630 --> 00:03:37,010
But what we can do is sort of hack around on this.

62
00:03:37,020 --> 00:03:42,300
We could turn this variable from a local variable into a global variable and global variables will work

63
00:03:42,300 --> 00:03:42,830
anywhere.

64
00:03:43,050 --> 00:03:45,970
So to do that, we just call global and then that variable.

65
00:03:45,990 --> 00:03:49,950
So if we save this and now run it, come back here.

66
00:03:49,950 --> 00:03:55,520
Python new at our original window, boom, we open it and boom here.

67
00:03:55,530 --> 00:03:56,940
Now it works, right?

68
00:03:57,720 --> 00:03:58,230
So.

69
00:03:59,400 --> 00:04:05,420
That's one way to do it, but you have to remember to do that, right, which is kind of a hassle.

70
00:04:05,850 --> 00:04:11,010
It's much better just to remember to use your new lube or your.

71
00:04:12,330 --> 00:04:15,540
Put a main loop running in your new window.

72
00:04:15,810 --> 00:04:19,920
Now, that main loop will be looping around inside of this function.

73
00:04:19,920 --> 00:04:26,670
So it doesn't matter if these are local variables and things that work, as we can see, by saving this

74
00:04:26,670 --> 00:04:28,020
and running it one last time.

75
00:04:31,110 --> 00:04:32,070
Here's our window.

76
00:04:33,080 --> 00:04:38,300
And boom, there's our picture, so just some weird little thing to keep in mind if you try and use

77
00:04:38,300 --> 00:04:44,030
an image on a new window and it doesn't work, chances are you forgot to instantiate a new.

78
00:04:45,270 --> 00:04:50,820
Main loop inside of your function where you're running your new level or your new top level window.

79
00:04:51,120 --> 00:04:52,560
So that's all there is to that.

80
00:04:53,810 --> 00:04:58,880
I just kind of fun, so in the next video, we'll look at the open file dialogue box.
