00:03
Good day, ladies and gentlemen.
00:06
Today, we're looking live at probe number 9 .6, and hear from our great python book.
00:16
And we are supposed to display a tick -tac -poe board.
00:23
And the basic idea, of course, is that we're supposed to create a tick -tac -poe board.
00:28
You can see an image of it in figure 9.
00:34
In the book.
00:37
And you're supposed to use the random int function, a randint, to choose an image which to display.
00:46
So before i show you the code, i'm going to go, i'm going to talk you through what went on, and then i'll give you an outline of what i did, and then i'll show you the code.
01:05
And then i'll run it.
01:07
Again, this time i have the code pre -written, and i'll show it to you once we're done and sort of just give you an idea of what it is.
01:18
But basically, i'm just going to talk you through it first.
01:23
Okay.
01:24
So the first thing we have to do when we're doing this, of course, is we have to create a tk object, so we have to, an instance of a tk, so we have to do a window equals to tk.
01:41
Okay.
01:43
And now on that window, we want to create a canvas object.
01:48
So we bring up a canvas object, canvas, and, you know, it's some with, in my case, i chose like 500 and a height.
02:03
Again i chose it to be a 500 you know these are the attributes of the canvas oh the most important attribute you have to always include is the window or where it should be located and whenever you you build a canvas object or whatever you always have to install it and to do that we have to do a so that puts the canvas object on the window.
02:39
Of course, that's using the geometry manager pack.
02:45
Okay, so.
02:50
And then, so what are we going to do? well, now, basically, what you have is you have this, let me see, let me go down a little bit here.
03:03
Let me go over here.
03:06
So you create this, you know, the instance of tkinter like this, the tk object.
03:16
Okay.
03:18
And then on there, we create the canvas.
03:25
So maybe i'll draw the canvas like this.
03:28
So the canvas, i probably should have drawn the window.
03:34
I guess is a broken bar.
03:38
Okay, so this is the inside one here is the canvas object.
03:47
So that's the canvas object.
03:54
Now, the way i did it anyhow is basically i broke the canvas object into essentially a three -by -three grid, if you will.
04:12
So we have this three -by -three grid, something like this.
04:21
And i numbered the...
04:29
So then this is the rows over here.
04:32
I had row zero, row one, row two.
04:37
And then, of course, the columns go zero, one and two.
04:44
And so i did a nested four loop iterating over the number or iterating over the rows and the columns.
04:59
And at each position, so each position, i would randomly choose an integer.
05:07
So at each position, each position, you choose, you choose random.
05:24
Random dot, randint.
05:29
Chooses a number between 0 and 1.
05:33
And remember it, sorry, it would choose a number 0 or 1.
05:39
Rand, inc includes the boundaries here, so we do, we would choose 0 or 1 here.
05:46
And then once that number is chosen, then that number corresponds to, say, zero corresponds or corresponds to the x image, x, gif, or xgif, and then xgif, and then one corresponds to the o gif, or o gif.
06:29
And i import that image, import that image, import that image using photo, sorry, photo image.
06:44
So important point here is with photo image, with photo image, you have to use gifts here...