WEBVTT

0
00:00.240 --> 00:05.220
Now we're at the final stretch. Our Pomodoro program is almost complete.

1
00:05.520 --> 00:07.740
We've got this beautiful user interface,

2
00:07.770 --> 00:11.520
we've got beautiful colors from our colorhunt.io color palette,

3
00:11.970 --> 00:15.600
and we've got pretty much everything functioning other than just some loose

4
00:15.600 --> 00:16.433
ends.

5
00:16.560 --> 00:21.000
So the first thing I want to fix is the section with the check marks. So

6
00:21.000 --> 00:22.890
we've created the checkmarks

7
00:22.920 --> 00:27.570
which is a label that currently just contains a single checkmark.

8
00:28.080 --> 00:33.080
Now I'm actually going to cut this checkmark and delete the text here because I

9
00:33.510 --> 00:37.140
want that label to start out as empty. Now,

10
00:37.170 --> 00:40.860
the only time when I want that label to get an extra check

11
00:40.860 --> 00:45.860
mark is when the user has completed a work countdown.

12
00:47.070 --> 00:49.980
So once they've completed their 25 minute session,

13
00:50.190 --> 00:53.850
then they should get that checkmark. To do that

14
00:53.880 --> 00:58.880
I'm going to write the code inside this else statement because every single time a

15
00:59.520 --> 01:00.990
countdown completes,

16
01:01.230 --> 01:05.610
it's going to go into this else statement because the count goes down to zero.

17
01:06.240 --> 01:10.710
Now, currently we're just getting the timer to restart itself and go to the next

18
01:10.740 --> 01:11.573
session.

19
01:11.910 --> 01:16.910
But what we want to do here is we want to check to see how many reps we have, and

20
01:18.450 --> 01:20.280
for every two reps

21
01:20.340 --> 01:25.340
then that means we've completed one work session because it's work then rest,

22
01:26.400 --> 01:29.820
then work, then rest. So for every two reps,

23
01:29.850 --> 01:32.790
we've completed one 25 minute work session.

24
01:33.630 --> 01:35.130
So here's a challenge for you.

25
01:35.610 --> 01:40.610
So have a think about how you can use our variable reps to check so that for

26
01:41.520 --> 01:44.040
every two reps we've completed,

27
01:44.340 --> 01:48.930
we add a checkmark to this checkmark label.

28
01:49.830 --> 01:52.710
Pause the video and see if you can complete this challenge,

29
01:52.830 --> 01:55.320
then test it out and see if you managed to get it right.

30
01:55.880 --> 01:56.713
<v 1>Okay.</v>

31
01:59.450 --> 01:59.810
<v 0>All right.</v>

32
01:59.810 --> 02:04.610
So we know that the reps is equal to the number of sessions we've had.

33
02:04.940 --> 02:07.130
So for example, if we've done for reps,

34
02:07.160 --> 02:10.490
then that means we've had two work sessions and two breaks.

35
02:11.030 --> 02:16.030
That means we can basically divide reps by two to get the total number of work

36
02:16.280 --> 02:17.210
sessions we've done.

37
02:17.930 --> 02:22.930
What I can do is I can create a temporary variable called mark,

38
02:23.450 --> 02:26.840
which is just going to be in an empty string to start off.

39
02:27.800 --> 02:31.490
And then I can create a for loop to loop through a range.

40
02:32.000 --> 02:36.950
And the range is going to go from zero up to our reps divided by 2.

41
02:37.880 --> 02:42.880
Now this is giving us a warning at the moment because reps divided by 2 or

42
02:42.920 --> 02:47.570
anything divided by anything becomes a floating type number.

43
02:48.140 --> 02:53.140
In our case we want to do is we want to use that math.floor again so that we

44
02:53.420 --> 02:58.370
can floor this reps divided by 2 to a whole number

45
02:58.930 --> 03:02.230
and that way we get the correct number of work sessions.

46
03:02.950 --> 03:05.500
If you want to make this a little bit more clear

47
03:05.680 --> 03:07.660
the next time you read your code,

48
03:07.720 --> 03:12.720
you can actually create a work_sessions and we can move this part of our code

49
03:14.470 --> 03:15.303
over to here.

50
03:15.850 --> 03:20.740
So the total number of work sessions is equal to the reps divided by 2 and

51
03:20.740 --> 03:23.050
then rounded down to the nearest integer.

52
03:23.590 --> 03:27.010
And then we can use that number of work sessions to create our range.

53
03:27.850 --> 03:29.260
When we've created our range,

54
03:29.290 --> 03:33.010
we know that this loop is going to run for that many times.

55
03:33.370 --> 03:38.370
So we can add to our mark. For every single time the loop runs,

56
03:38.890 --> 03:41.680
I'm going to paste in a checkmark.

57
03:42.220 --> 03:45.580
You should have that checkmark that you had from a previously,

58
03:45.790 --> 03:49.150
and you can paste it into here. Now,

59
03:49.150 --> 03:54.100
once we've completed that loop, then all we need to do is the update

60
03:54.160 --> 03:59.160
our checkmarks label by calling config and then changing the text to equal our

61
04:00.580 --> 04:02.710
mark. Now, in this case,

62
04:02.710 --> 04:05.740
it probably makes sense for that to actually be plural.

63
04:06.040 --> 04:08.350
So I'm gonna use my refactor -> rename

64
04:08.440 --> 04:12.130
to just add an 's' to everywhere I'm using this.

65
04:13.540 --> 04:17.710
Now let's test it out. When I hit start,

66
04:17.770 --> 04:22.660
it should start counting down. And once that work session completes,

67
04:22.990 --> 04:27.580
then you'll see the timer go to zero and our first checkmark show up.

68
04:28.510 --> 04:32.800
And for every work session we complete, we get an extra checkmark

69
04:33.010 --> 04:36.220
just to nudge us towards working a little bit harder.

70
04:37.390 --> 04:42.370
The final thing that I want to address is our reset mechanism.

71
04:42.910 --> 04:45.220
So we have this lovely reset button,

72
04:45.250 --> 04:47.410
but it's not really doing anything at the moment.

73
04:48.070 --> 04:51.640
What I'm going to do is create a new function here

74
04:51.670 --> 04:53.860
which I'll call reset_timer.

75
04:54.760 --> 04:59.760
And what this reset_timer is going to do is basically it's going to reset all

76
04:59.770 --> 05:04.330
the checkmarks, reset the text inside the timer,

77
05:04.600 --> 05:09.600
stop the timer and change this title back to the text that it originally had,

78
05:10.630 --> 05:14.350
which is just the word timer. Now,

79
05:14.470 --> 05:19.450
the hardest part about this is actually stopping the timer because what we have

80
05:19.450 --> 05:23.740
to do is we actually need to tap into that window.after again.

81
05:24.280 --> 05:26.080
But instead of calling after,

82
05:26.140 --> 05:30.130
we actually want to call after_cancel. This way

83
05:30.160 --> 05:34.510
we can actually cancel the timer that we had set up previously.

84
05:35.920 --> 05:40.750
This is the thing that we want to cancel. And if we want to cancel it,

85
05:40.870 --> 05:44.140
we have to give it a name and we have to put it inside a variable.

86
05:44.920 --> 05:46.990
So I'm going to call this my timer.

87
05:47.620 --> 05:52.620
But because this is going to be a local variable because it's created inside

88
05:52.990 --> 05:56.500
this particular function, I actually have to bring it out.

89
05:56.530 --> 06:01.370
I have to make it a global variable, so after create it up here,

90
06:01.730 --> 06:04.910
but what value do I give it? Well, initially,

91
06:04.970 --> 06:07.280
it's actually not going to have any value at all.

92
06:07.550 --> 06:11.480
So it's going to start out as none. And then later on,

93
06:11.540 --> 06:16.540
I'm going to tap into that global timer in order to get it to hold on to this.

94
06:19.220 --> 06:23.840
Now, then once I want to reset my timer and cancel it, well

95
06:23.840 --> 06:28.840
then I can actually tap into this global timer and stop the timer.

96
06:29.900 --> 06:34.340
So now to actually activate this function, reset_timer,

97
06:34.700 --> 06:38.360
we have to add it as a command to our reset button.

98
06:38.900 --> 06:42.230
So where we create our button, I'm gonna add it as a command.

99
06:42.680 --> 06:45.080
And remember, we have to get rid of the parentheses.

100
06:45.680 --> 06:49.490
So now if I run my program and I start my timer,

101
06:49.820 --> 06:53.240
you can see that as soon as I click this reset button,

102
06:53.570 --> 06:57.230
it stops my timer and it doesn't continue.

103
06:57.950 --> 07:00.590
So now all we have to do is the add

104
07:00.590 --> 07:05.180
all of the things that we have to reset, for example, the text in here,

105
07:05.420 --> 07:07.850
we want that to read 00.

106
07:09.140 --> 07:11.390
So that was the timer_text from our canvas.

107
07:11.780 --> 07:15.170
And then the other thing we want to do is the title label.

108
07:15.350 --> 07:18.350
We want to set that to just read timer.

109
07:20.270 --> 07:21.320
And finally,

110
07:21.380 --> 07:26.380
we want to reset our check marks so that once you hit the reset button,

111
07:26.810 --> 07:28.850
it resets this title label,

112
07:29.120 --> 07:34.120
the timer text here stops the timer and gets rid of all the checkmarks, like

113
07:35.360 --> 07:39.080
this. Pause the video and give that a go.

114
07:42.290 --> 07:45.860
Alright. So the first thing we want to change is our timer text.

115
07:46.250 --> 07:48.860
And because the timer text is created in the canvas,

116
07:48.890 --> 07:50.990
we have a slightly different way of changing that.

117
07:51.440 --> 07:53.900
So we call canvas.itemconfig,

118
07:54.200 --> 07:57.830
and then pass in the thing that we want to change, which is the timer text.

119
07:58.220 --> 08:02.000
And then the attribute that we want to change, which is it's text.

120
08:02.390 --> 08:06.590
And then we change that to just say 00:00,

121
08:07.100 --> 08:11.300
go back to the beginning. Now the title label is a lot easier to change.

122
08:11.360 --> 08:13.700
We can say title_label.config,

123
08:14.030 --> 08:18.140
and then we can configure its text to basically just read timer.

124
08:18.860 --> 08:21.350
Finally, we're going to reset our checkmarks.

125
08:21.410 --> 08:24.560
So we tap into our checkmarks' label again,

126
08:24.560 --> 08:28.880
using config to change the text back to empty.

127
08:30.500 --> 08:33.140
However, there's still a slight problem with our code.

128
08:33.440 --> 08:36.010
What happens if while our timer is counting down

129
08:36.020 --> 08:39.320
I hit the reset button and then hit the start button again?

130
08:40.580 --> 08:46.790
Did you spot that? Our timer jumped from "Work" to "Break" because our reps are still increasing.

131
08:47.690 --> 08:51.710
So far we haven't reset the number of reps to zero when we reset the timer.

132
08:51.830 --> 08:56.120
So all we need to do to fix this bug is add: global reps

133
08:56.390 --> 08:59.450
reps = 0  to the reset time function.

134
09:00.500 --> 09:09.380
That's all there is to it! Now if we reset our WORK_MIN to 25, SHORT_BREAK 5, LONG_BREAK 20 or whatever

135
09:09.380 --> 09:16.520
it is that you want it to be. Then once we hit run, we will end up with our final Pomodoro timer.

136
09:16.970 --> 09:24.200
And it will be now ready for you to start practicing doing Pomodoros and improving your work and your

137
09:24.200 --> 09:25.030
productivity.

138
09:25.700 --> 09:32.780
So I hope you enjoyed making this fully functional tkinter application with me and that I hope you

139
09:32.780 --> 09:39.710
will modify this, customize it, make it truly your own and be able to show off to us what it is that

140
09:39.710 --> 09:46.130
you have done. Because this really is a useful application that you can use or you can get your friends

141
09:46.130 --> 09:49.430
and your family to start using and show off your hard work.