1 00:00:00,262 --> 00:00:03,780 All right so to do my polling, I'm actually gonna make a new method and 2 00:00:03,780 --> 00:00:04,890 I'm gonna call it update. 3 00:00:06,500 --> 00:00:09,272 And let's just print updated. 4 00:00:09,272 --> 00:00:10,760 All right and 5 00:00:10,760 --> 00:00:16,250 then we want to make sure that our update method gets called every second. 6 00:00:17,430 --> 00:00:22,110 And what's cool is that our global app, the thing we called master, 7 00:00:22,110 --> 00:00:25,340 in here self.master, I know we called it root on the outside. 8 00:00:25,340 --> 00:00:30,340 It has a method called after and 9 00:00:30,340 --> 00:00:34,930 it will fire off after a certain number of milliseconds. 10 00:00:34,930 --> 00:00:35,990 So let's use that. 11 00:00:35,990 --> 00:00:40,140 So we'll say self.master.after and then, 12 00:00:40,140 --> 00:00:42,930 we're supposed to find the number of milliseconds. 13 00:00:42,930 --> 00:00:46,790 So 1000 milliseconds is one second. 14 00:00:46,790 --> 00:00:50,390 And then we want that to run self.update. 15 00:00:50,390 --> 00:00:55,610 Okay, so we had 1000 milliseconds, or one second, and then we run update again. 16 00:00:55,610 --> 00:01:01,594 All right, so after all the stuff gets built, then we run self.update. 17 00:01:02,870 --> 00:01:05,510 Okay, so now run. 18 00:01:07,160 --> 00:01:09,920 And every second, the window is off screen. 19 00:01:09,920 --> 00:01:12,870 Every second, it prints out updated. 20 00:01:12,870 --> 00:01:15,290 Cool so, that's great. 21 00:01:15,290 --> 00:01:16,480 We know that works. 22 00:01:16,480 --> 00:01:20,220 In this method, is where I want to decrement the timer. 23 00:01:20,220 --> 00:01:23,640 So first let's get how much time is left. 24 00:01:24,790 --> 00:01:29,555 And we'll say time_left = self.time_left.get() so 25 00:01:29,555 --> 00:01:30,930 we're just holding onto it. 26 00:01:30,930 --> 00:01:34,360 That's just easier to type than self.time_left all the time. 27 00:01:34,360 --> 00:01:40,600 So for running, and there's time left, so if self.running and 28 00:01:40,600 --> 00:01:43,630 time_left so time left isn't zero, 29 00:01:45,280 --> 00:01:49,280 then we want to take one second off of the number. 30 00:01:49,280 --> 00:01:55,234 So, we'll do self.time and left.set to time left -1. 31 00:01:55,234 --> 00:01:58,155 Otherwise, so 32 00:01:58,155 --> 00:02:02,840 else, we just wanna set running to false and then reset the buttons. 33 00:02:02,840 --> 00:02:05,315 So, we can just call self.stop_timer. 34 00:02:07,190 --> 00:02:08,650 Because that does what we want. 35 00:02:08,650 --> 00:02:12,220 It turns running to false and resets the buttons. 36 00:02:12,220 --> 00:02:14,470 So if we're running and there's time left. 37 00:02:14,470 --> 00:02:16,870 Let's take a second off the time left number. 38 00:02:16,870 --> 00:02:20,470 Otherwise let's just call our stop timer method to reset the buttons and 39 00:02:20,470 --> 00:02:21,320 turn off the running variable. 40 00:02:22,390 --> 00:02:26,920 All right so now we need to make sure that our timer, like we haven't even been 41 00:02:26,920 --> 00:02:30,490 showing the timer label at all, it's just been blank because there's no text. 42 00:02:30,490 --> 00:02:35,290 So we need to make sure that updates with how much time is actually left. 43 00:02:35,290 --> 00:02:39,530 So we should tell the variable that controls the text of the timer label 44 00:02:39,530 --> 00:02:41,090 to watch for changes. 45 00:02:41,090 --> 00:02:44,330 And then when it changes to redraw the label. 46 00:02:44,330 --> 00:02:51,340 So now we're already drawing the label right here in our build timer method. 47 00:02:51,340 --> 00:02:54,470 We need to tell the method, since we're gonna, so 48 00:02:54,470 --> 00:02:58,602 first of all let's come up here, let's do this one step at a time. 49 00:02:58,602 --> 00:03:05,600 All right so here is where we made our timer text variable. 50 00:03:06,690 --> 00:03:12,338 So this is the text that we display. 51 00:03:12,338 --> 00:03:17,440 So we wanna tell this text that whenever 52 00:03:17,440 --> 00:03:22,980 it gets updated to go do some of it. 53 00:03:22,980 --> 00:03:26,150 All right, so w means whenever this was written to. 54 00:03:27,400 --> 00:03:31,190 Then we wanna call self.build_timer. 55 00:03:31,190 --> 00:03:35,617 Okay, so go down here to self.build_timer. 56 00:03:35,617 --> 00:03:39,984 So build_timer is now gonna get called by itself. 57 00:03:39,984 --> 00:03:42,940 But it's also gonna get called whenever that trace fires. 58 00:03:42,940 --> 00:03:46,300 And when that trace fires, it sends some more information as well. 59 00:03:46,300 --> 00:03:49,510 So we have to accept args. 60 00:03:49,510 --> 00:03:54,090 We're not going to use these args at all we don't care about them but 61 00:03:54,090 --> 00:03:57,600 we have to except them because python has the rule that like you have to know 62 00:03:57,600 --> 00:03:58,750 how many variables are coming in. 63 00:04:00,250 --> 00:04:04,730 So anytime the timer updates were going to call build timer. 64 00:04:04,730 --> 00:04:08,454 Any time the timer text updates okay. 65 00:04:08,454 --> 00:04:11,493 So, let's go update that label. 66 00:04:11,493 --> 00:04:18,870 So here in update we are going to the minutes and seconds that are left. 67 00:04:20,090 --> 00:04:24,400 So I'm actually going to make another method here. 68 00:04:24,400 --> 00:04:26,674 I'm gonna call it minutes_seconds. 69 00:04:27,780 --> 00:04:30,950 And it's going to take seconds which is a going to be a number of seconds. 70 00:04:31,990 --> 00:04:35,580 And I want to return the minutes which should be the int version 71 00:04:35,580 --> 00:04:37,060 of seconds divided by 60. 72 00:04:37,060 --> 00:04:43,470 I could also do seconds // 60 which will do int division. 73 00:04:43,470 --> 00:04:47,300 And then I want the int version of seconds modulo 60. 74 00:04:47,300 --> 00:04:50,760 Modulo gives us effectively the remainder. 75 00:04:50,760 --> 00:04:52,080 So we're gonna return minutes. 76 00:04:52,080 --> 00:04:53,620 And we're gonna return seconds. 77 00:04:55,100 --> 00:05:00,636 All right, so down here, inside the time left, let's do minutes, 78 00:05:00,636 --> 00:05:04,798 seconds = self.minutes_second. 79 00:05:04,798 --> 00:05:09,333 And we're gonna pass in (time_left) cuz that's how much time is left, right? 80 00:05:09,333 --> 00:05:13,376 And then we're gonna do self.timer_text.set(). 81 00:05:13,376 --> 00:05:15,930 And I want to set this timer text to something. 82 00:05:17,030 --> 00:05:19,760 Normally we would do like this because we want minutes and seconds but 83 00:05:19,760 --> 00:05:20,600 we want to format this. 84 00:05:20,600 --> 00:05:24,170 So I want zeros padded out to two digits. 85 00:05:25,470 --> 00:05:29,350 And then again zeros added out to two digits. 86 00:05:30,390 --> 00:05:30,890 There we go. 87 00:05:31,890 --> 00:05:34,282 And then I call format with minutes and seconds. 88 00:05:34,282 --> 00:05:39,150 All right and then we need to do this again. 89 00:05:40,650 --> 00:05:43,630 Let's just copy this thing here all over again. 90 00:05:45,920 --> 00:05:47,170 End it before the timers stop. 91 00:05:47,170 --> 00:05:51,445 But instead of time left here, we're going to do it with 92 00:05:51,445 --> 00:05:58,420 DEFAULT_GAP and then we get that same text in there. 93 00:05:59,450 --> 00:06:03,080 Okay, this could probably be optimized if we wanted to move it in 94 00:06:03,080 --> 00:06:04,970 out of the if else. 95 00:06:04,970 --> 00:06:07,628 But for now let's just not worry about it, okay. 96 00:06:07,628 --> 00:06:10,830 [LAUGH] So that should do the work that we needed it to do. 97 00:06:10,830 --> 00:06:12,530 And this should make our timer count down. 98 00:06:12,530 --> 00:06:14,369 Let's see, let's run this. 99 00:06:16,300 --> 00:06:17,795 Bring one over here, let's hit Start. 100 00:06:21,420 --> 00:06:22,020 What do you know? 101 00:06:22,020 --> 00:06:25,330 Look at that, it's counting down by seconds, more or less. 102 00:06:26,990 --> 00:06:32,130 All right let's test what happens when this runs out. 103 00:06:32,130 --> 00:06:35,410 But to do that, I don't wanna wait 25 minutes. 104 00:06:35,410 --> 00:06:39,038 So let's do a new default gap and we'll just say, five seconds. 105 00:06:39,038 --> 00:06:44,570 All right, so run this again. 106 00:06:46,460 --> 00:06:54,190 And so all right, we've got five seconds left, hit start, four, three, two, one. 107 00:06:54,190 --> 00:06:55,430 Boop, and it, hey, look at that. 108 00:06:55,430 --> 00:06:56,200 It reset. 109 00:06:56,200 --> 00:07:00,000 The stop button is effectively clicked, gonna start, gonna go back to five. 110 00:07:00,000 --> 00:07:01,450 So that's cool, that's awesome. 111 00:07:01,450 --> 00:07:03,450 Now, let's see about setting up an alert.