00:01
Okay, for this problem, they'd like us to write a small app that draws two circles on the screen.
00:08
We're allowed to drag the circles around within the window, and we have a little label that we will update, depending on whether or not the circles intersect.
00:21
So first we're going to create our main app class here.
00:28
Let's see, we're going to create a window.
00:33
Using tk and let's go ahead and give our window a title.
00:42
Call it overlapping circles.
00:48
Let's see, let's add the label.
00:56
We're saving it to the class so that we can keep track of it and change it later.
01:05
Okay, pass the window, text.
01:10
We're going to initialize to two circles do not intersect.
01:21
Actually, since we're going to be changing, these messages around let's go ahead and save these messages so that we can use them the same each time so we'll call this message no intersect and we'll create another one for intersect and then let's go ahead and pack that label okay now we're going to want to add a canvas drawing on so this we are also going to keep track of we'll save it to the canvas variable.
02:25
Let's see.
02:29
Pick our canvas 400 by 250 and then we'll pack that one in as well.
02:53
Now for the circles, let's see, let's go ahead and define some x, y, and radius values.
03:12
For circle one, let's put it at 100, 100.
03:19
I'll put it on the left.
03:19
I'll put it on the left of the screen and we'll give the radius of 50.
03:27
We'll save the circle representation.
03:31
It will be our circle 2d to self .c1.
03:43
Okay, and then we're gonna go ahead and draw that on the canvas.
03:48
And we wanna keep track of this oval that gets created so that we can move it around later.
03:53
So we're gonna save that to oval one.
04:08
And we're going to specify the corners of the radiate of the oval.
04:13
So it's going to be x minus r, y minus r, x plus r, y plus r, and we also want to have a label to identify it from the other circle.
04:35
So we'll call this t1, text 1, can this got create text.
04:45
It's going to go at x comma y, and the text will be c1.
04:57
Circle we're just going to do the same thing but with different values we're going to put this one at 300 100 and we'll give it a radius of 75 and we'll save it to c2 oval 2 t 2 and change the label c2 once we've done that we want to bind some click handlers so we've got button one will just be a click.
05:49
We'll just pass the name of the method instead of calling it again.
05:56
And then we also want to bind to b1 motion, which will be our drag.
06:04
And we're actually going to do it all in the same handler, so we'll just pass it the same function.
06:13
And then we can start the main loop.
06:16
Down here in our click handler, which is the next important thing, i've written a couple utilities, functions that are going to help us out when doing this click handler.
06:29
This inside circle function just computes whether or not the click was inside a given circle...