1
00:00:00,240 --> 00:00:05,220
Now we're at the final stretch. Our Pomodoro program is almost complete.

2
00:00:05,520 --> 00:00:07,740
We've got this beautiful user interface,

3
00:00:07,770 --> 00:00:11,520
we've got beautiful colors from our colorhunt.io color palette,

4
00:00:11,970 --> 00:00:15,600
and we've got pretty much everything functioning other than just some loose

5
00:00:15,600 --> 00:00:16,433
ends.

6
00:00:16,560 --> 00:00:21,000
So the first thing I want to fix is the section with the check marks. So

7
00:00:21,000 --> 00:00:22,890
we've created the checkmarks

8
00:00:22,920 --> 00:00:27,570
which is a label that currently just contains a single checkmark.

9
00:00:28,080 --> 00:00:33,080
Now I'm actually going to cut this checkmark and delete the text here because I

10
00:00:33,510 --> 00:00:37,140
want that label to start out as empty. Now,

11
00:00:37,170 --> 00:00:40,860
the only time when I want that label to get an extra check

12
00:00:40,860 --> 00:00:45,860
mark is when the user has completed a work countdown.

13
00:00:47,070 --> 00:00:49,980
So once they've completed their 25 minute session,

14
00:00:50,190 --> 00:00:53,850
then they should get that checkmark. To do that

15
00:00:53,880 --> 00:00:58,880
I'm going to write the code inside this else statement because every single time a

16
00:00:59,520 --> 00:01:00,990
countdown completes,

17
00:01:01,230 --> 00:01:05,610
it's going to go into this else statement because the count goes down to zero.

18
00:01:06,240 --> 00:01:10,710
Now, currently we're just getting the timer to restart itself and go to the next

19
00:01:10,740 --> 00:01:11,573
session.

20
00:01:11,910 --> 00:01:16,910
But what we want to do here is we want to check to see how many reps we have, and

21
00:01:18,450 --> 00:01:20,280
for every two reps

22
00:01:20,340 --> 00:01:25,340
then that means we've completed one work session because it's work then rest,

23
00:01:26,400 --> 00:01:29,820
then work, then rest. So for every two reps,

24
00:01:29,850 --> 00:01:32,790
we've completed one 25 minute work session.

25
00:01:33,630 --> 00:01:35,130
So here's a challenge for you.

26
00:01:35,610 --> 00:01:40,610
So have a think about how you can use our variable reps to check so that for

27
00:01:41,520 --> 00:01:44,040
every two reps we've completed,

28
00:01:44,340 --> 00:01:48,930
we add a checkmark to this checkmark label.

29
00:01:49,830 --> 00:01:52,710
Pause the video and see if you can complete this challenge,

30
00:01:52,830 --> 00:01:55,320
then test it out and see if you managed to get it right.

31
00:01:55,880 --> 00:01:56,713
Okay.

32
00:01:59,450 --> 00:01:59,810
All right.

33
00:01:59,810 --> 00:02:04,610
So we know that the reps is equal to the number of sessions we've had.

34
00:02:04,940 --> 00:02:07,130
So for example, if we've done for reps,

35
00:02:07,160 --> 00:02:10,490
then that means we've had two work sessions and two breaks.

36
00:02:11,030 --> 00:02:16,030
That means we can basically divide reps by two to get the total number of work

37
00:02:16,280 --> 00:02:17,210
sessions we've done.

38
00:02:17,930 --> 00:02:22,930
What I can do is I can create a temporary variable called mark,

39
00:02:23,450 --> 00:02:26,840
which is just going to be in an empty string to start off.

40
00:02:27,800 --> 00:02:31,490
And then I can create a for loop to loop through a range.

41
00:02:32,000 --> 00:02:36,950
And the range is going to go from zero up to our reps divided by 2.

42
00:02:37,880 --> 00:02:42,880
Now this is giving us a warning at the moment because reps divided by 2 or

43
00:02:42,920 --> 00:02:47,570
anything divided by anything becomes a floating type number.

44
00:02:48,140 --> 00:02:53,140
In our case we want to do is we want to use that math.floor again so that we

45
00:02:53,420 --> 00:02:58,370
can floor this reps divided by 2 to a whole number

46
00:02:58,930 --> 00:03:02,230
and that way we get the correct number of work sessions.

47
00:03:02,950 --> 00:03:05,500
If you want to make this a little bit more clear

48
00:03:05,680 --> 00:03:07,660
the next time you read your code,

49
00:03:07,720 --> 00:03:12,720
you can actually create a work_sessions and we can move this part of our code

50
00:03:14,470 --> 00:03:15,303
over to here.

51
00:03:15,850 --> 00:03:20,740
So the total number of work sessions is equal to the reps divided by 2 and

52
00:03:20,740 --> 00:03:23,050
then rounded down to the nearest integer.

53
00:03:23,590 --> 00:03:27,010
And then we can use that number of work sessions to create our range.

54
00:03:27,850 --> 00:03:29,260
When we've created our range,

55
00:03:29,290 --> 00:03:33,010
we know that this loop is going to run for that many times.

56
00:03:33,370 --> 00:03:38,370
So we can add to our mark. For every single time the loop runs,

57
00:03:38,890 --> 00:03:41,680
I'm going to paste in a checkmark.

58
00:03:42,220 --> 00:03:45,580
You should have that checkmark that you had from a previously,

59
00:03:45,790 --> 00:03:49,150
and you can paste it into here. Now,

60
00:03:49,150 --> 00:03:54,100
once we've completed that loop, then all we need to do is the update

61
00:03:54,160 --> 00:03:59,160
our checkmarks label by calling config and then changing the text to equal our

62
00:04:00,580 --> 00:04:02,710
mark. Now, in this case,

63
00:04:02,710 --> 00:04:05,740
it probably makes sense for that to actually be plural.

64
00:04:06,040 --> 00:04:08,350
So I'm gonna use my refactor -> rename

65
00:04:08,440 --> 00:04:12,130
to just add an 's' to everywhere I'm using this.

66
00:04:13,540 --> 00:04:17,709
Now let's test it out. When I hit start,

67
00:04:17,769 --> 00:04:22,660
it should start counting down. And once that work session completes,

68
00:04:22,990 --> 00:04:27,580
then you'll see the timer go to zero and our first checkmark show up.

69
00:04:28,510 --> 00:04:32,800
And for every work session we complete, we get an extra checkmark

70
00:04:33,010 --> 00:04:36,220
just to nudge us towards working a little bit harder.

71
00:04:37,390 --> 00:04:42,370
The final thing that I want to address is our reset mechanism.

72
00:04:42,910 --> 00:04:45,220
So we have this lovely reset button,

73
00:04:45,250 --> 00:04:47,410
but it's not really doing anything at the moment.

74
00:04:48,070 --> 00:04:51,640
What I'm going to do is create a new function here

75
00:04:51,670 --> 00:04:53,860
which I'll call reset_timer.

76
00:04:54,760 --> 00:04:59,760
And what this reset_timer is going to do is basically it's going to reset all

77
00:04:59,770 --> 00:05:04,330
the checkmarks, reset the text inside the timer,

78
00:05:04,600 --> 00:05:09,600
stop the timer and change this title back to the text that it originally had,

79
00:05:10,630 --> 00:05:14,350
which is just the word timer. Now,

80
00:05:14,470 --> 00:05:19,450
the hardest part about this is actually stopping the timer because what we have

81
00:05:19,450 --> 00:05:23,740
to do is we actually need to tap into that window.after again.

82
00:05:24,280 --> 00:05:26,080
But instead of calling after,

83
00:05:26,140 --> 00:05:30,130
we actually want to call after_cancel. This way

84
00:05:30,160 --> 00:05:34,510
we can actually cancel the timer that we had set up previously.

85
00:05:35,920 --> 00:05:40,750
This is the thing that we want to cancel. And if we want to cancel it,

86
00:05:40,870 --> 00:05:44,140
we have to give it a name and we have to put it inside a variable.

87
00:05:44,920 --> 00:05:46,990
So I'm going to call this my timer.

88
00:05:47,620 --> 00:05:52,620
But because this is going to be a local variable because it's created inside

89
00:05:52,990 --> 00:05:56,500
this particular function, I actually have to bring it out.

90
00:05:56,530 --> 00:06:01,370
I have to make it a global variable, so after create it up here,

91
00:06:01,730 --> 00:06:04,910
but what value do I give it? Well, initially,

92
00:06:04,970 --> 00:06:07,280
it's actually not going to have any value at all.

93
00:06:07,550 --> 00:06:11,480
So it's going to start out as none. And then later on,

94
00:06:11,540 --> 00:06:16,540
I'm going to tap into that global timer in order to get it to hold on to this.

95
00:06:19,220 --> 00:06:23,840
Now, then once I want to reset my timer and cancel it, well

96
00:06:23,840 --> 00:06:28,840
then I can actually tap into this global timer and stop the timer.

97
00:06:29,900 --> 00:06:34,340
So now to actually activate this function, reset_timer,

98
00:06:34,700 --> 00:06:38,360
we have to add it as a command to our reset button.

99
00:06:38,900 --> 00:06:42,230
So where we create our button, I'm gonna add it as a command.

100
00:06:42,680 --> 00:06:45,080
And remember, we have to get rid of the parentheses.

101
00:06:45,680 --> 00:06:49,490
So now if I run my program and I start my timer,

102
00:06:49,820 --> 00:06:53,240
you can see that as soon as I click this reset button,

103
00:06:53,570 --> 00:06:57,230
it stops my timer and it doesn't continue.

104
00:06:57,950 --> 00:07:00,590
So now all we have to do is the add

105
00:07:00,590 --> 00:07:05,180
all of the things that we have to reset, for example, the text in here,

106
00:07:05,420 --> 00:07:07,850
we want that to read 00.

107
00:07:09,140 --> 00:07:11,390
So that was the timer_text from our canvas.

108
00:07:11,780 --> 00:07:15,170
And then the other thing we want to do is the title label.

109
00:07:15,350 --> 00:07:18,350
We want to set that to just read timer.

110
00:07:20,270 --> 00:07:21,320
And finally,

111
00:07:21,380 --> 00:07:26,380
we want to reset our check marks so that once you hit the reset button,

112
00:07:26,810 --> 00:07:28,850
it resets this title label,

113
00:07:29,120 --> 00:07:34,120
the timer text here stops the timer and gets rid of all the checkmarks, like

114
00:07:35,360 --> 00:07:39,080
this. Pause the video and give that a go.

115
00:07:42,290 --> 00:07:45,860
Alright. So the first thing we want to change is our timer text.

116
00:07:46,250 --> 00:07:48,860
And because the timer text is created in the canvas,

117
00:07:48,890 --> 00:07:50,990
we have a slightly different way of changing that.

118
00:07:51,440 --> 00:07:53,900
So we call canvas.itemconfig,

119
00:07:54,200 --> 00:07:57,830
and then pass in the thing that we want to change, which is the timer text.

120
00:07:58,220 --> 00:08:02,000
And then the attribute that we want to change, which is it's text.

121
00:08:02,390 --> 00:08:06,590
And then we change that to just say 00:00,

122
00:08:07,100 --> 00:08:11,300
go back to the beginning. Now the title label is a lot easier to change.

123
00:08:11,360 --> 00:08:13,700
We can say title_label.config,

124
00:08:14,030 --> 00:08:18,140
and then we can configure its text to basically just read timer.

125
00:08:18,860 --> 00:08:21,350
Finally, we're going to reset our checkmarks.

126
00:08:21,410 --> 00:08:24,560
So we tap into our checkmarks' label again,

127
00:08:24,560 --> 00:08:28,880
using config to change the text back to empty.

128
00:08:30,500 --> 00:08:33,140
However, there's still a slight problem with our code.

129
00:08:33,440 --> 00:08:36,010
What happens if while our timer is counting down

130
00:08:36,020 --> 00:08:39,320
I hit the reset button and then hit the start button again?

131
00:08:40,580 --> 00:08:46,790
Did you spot that? Our timer jumped from "Work" to "Break" because our reps are still increasing.

132
00:08:47,690 --> 00:08:51,710
So far we haven't reset the number of reps to zero when we reset the timer.

133
00:08:51,830 --> 00:08:56,120
So all we need to do to fix this bug is add: global reps

134
00:08:56,390 --> 00:08:59,450
reps = 0  to the reset time function.

135
00:09:00,500 --> 00: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

136
00:09:09,380 --> 00: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.

137
00:09:16,970 --> 00:09:24,200
And it will be now ready for you to start practicing doing Pomodoros and improving your work and your

138
00:09:24,200 --> 00:09:25,030
productivity.

139
00:09:25,700 --> 00:09:32,780
So I hope you enjoyed making this fully functional tkinter application with me and that I hope you

140
00:09:32,780 --> 00: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

141
00:09:39,710 --> 00:09:46,130
you have done. Because this really is a useful application that you can use or you can get your friends

142
00:09:46,130 --> 00:09:49,430
and your family to start using and show off your hard work.

