1 00:00:00,660 --> 00:00:03,340 Hello and welcome to this video. 2 00:00:03,360 --> 00:00:12,310 This is gonna be a three part video series where we are going to create a count down timer using Python. 3 00:00:12,360 --> 00:00:15,210 Calm down time has a very useful. 4 00:00:15,240 --> 00:00:19,860 You can use that to count down to several events for example. 5 00:00:19,860 --> 00:00:29,240 Holidays and other related events that are of interest to you to begin our development. 6 00:00:29,240 --> 00:00:33,840 You need to open up the python shell and you can access it. 7 00:00:33,840 --> 00:00:42,930 Fi your programs menu inside the python folder there is the idol just double click on the idle and that 8 00:00:42,930 --> 00:00:44,190 will open up this shell. 9 00:00:44,640 --> 00:00:48,840 So once you've got the shell open we need to open up a new window. 10 00:00:49,260 --> 00:00:58,980 So you go file a new file and inside this area here we will develop our application. 11 00:00:58,980 --> 00:01:07,430 So the first thing you need to do is save the file so you do file save as and you can save it anywhere 12 00:01:07,470 --> 00:01:16,110 you like but just save it with a dot P Y extension actually you don't need to because it's already done 13 00:01:16,110 --> 00:01:18,980 that for you here or you need to just give it a name. 14 00:01:19,140 --> 00:01:29,240 So I'm going to call my count down and I'll just save it and I'll save it on my desktop. 15 00:01:30,790 --> 00:01:32,440 OK. 16 00:01:32,670 --> 00:01:37,580 So I've got the file so this now is a python file. 17 00:01:37,830 --> 00:01:40,950 I want to use some Python libraries. 18 00:01:41,070 --> 00:01:44,480 So before I use them I need to import them. 19 00:01:44,520 --> 00:01:55,220 I'm going to import t counter which is a module that is used to create user interfaces of various types. 20 00:01:55,410 --> 00:02:04,810 So to import that I just need to type typing from space teak into 21 00:02:10,050 --> 00:02:15,320 King ter can't spell today Kintore. 22 00:02:15,620 --> 00:02:18,650 That's it from TI Kintore. 23 00:02:18,810 --> 00:02:21,000 They type in the word import 24 00:02:23,930 --> 00:02:26,730 space Asterix. 25 00:02:26,990 --> 00:02:35,790 So with the asterisks it will import the library mix who want to import whole nother library. 26 00:02:35,800 --> 00:02:48,210 It's also a subset of T Kintore to do to take into space import space. 27 00:02:48,230 --> 00:02:52,150 This one's called t t k. 28 00:02:52,310 --> 00:02:57,090 Next we won't import a t type font. 29 00:02:57,140 --> 00:03:12,020 So we can use a font from t kin to you type in the word import followed by or too important to import 30 00:03:12,020 --> 00:03:13,650 in the font element. 31 00:03:13,730 --> 00:03:20,220 Next I want to import the time module so I'm just typing. 32 00:03:20,270 --> 00:03:28,310 Import time I also want to import the date time so I type import 33 00:03:31,140 --> 00:03:34,680 date time. 34 00:03:34,780 --> 00:03:35,180 All right. 35 00:03:35,190 --> 00:03:40,870 So I've got all my libraries and class methods ready. 36 00:03:40,950 --> 00:03:44,090 First thing I want to do is create a variable. 37 00:03:44,140 --> 00:03:51,360 It's gonna be a global variable a global variable means it will be available throughout the application 38 00:03:52,470 --> 00:04:00,780 Python variables are scope base where you can have a variable that is local or exist only within the 39 00:04:00,780 --> 00:04:07,140 module but by declaring it global that means I want the available throughout the application so I just 40 00:04:07,140 --> 00:04:11,990 type in the word global followed by the name I want to call it. 41 00:04:12,000 --> 00:04:17,800 I'm going to call it and times who will use that later in the application. 42 00:04:17,840 --> 00:04:24,930 So I want to create our first function here and to create a function you type in D F followed by the 43 00:04:24,930 --> 00:04:25,560 name. 44 00:04:25,890 --> 00:04:37,470 I'm going to call this can't underscore wait I'm going to be the name of my function actually before 45 00:04:37,530 --> 00:04:45,500 I create that function I want to create another one of us not create a function called quit. 46 00:04:45,750 --> 00:04:55,580 This will allow us to quit the application and inside the parentheses I'm going to pass it arguments. 47 00:04:56,380 --> 00:04:56,870 Okay. 48 00:04:56,880 --> 00:05:08,460 And that's it and semicolon you use the asterisks and the KRG is which stands for argument. 49 00:05:08,460 --> 00:05:17,490 So what you normally do when you're not sure how many arguments might be passed to your function you 50 00:05:17,490 --> 00:05:20,490 used the asterisks and eggs. 51 00:05:20,710 --> 00:05:31,470 What that does it allows you to pass an arbitrary number of arguments to your function and inside this 52 00:05:31,470 --> 00:05:33,110 quit function. 53 00:05:33,120 --> 00:05:41,610 I'm going to had a root metros and was a root dot this Troy 54 00:05:45,870 --> 00:05:55,140 what the root dot destroyed does it will cause the main loop of the application to exit. 55 00:05:55,180 --> 00:06:02,790 So when the application kept running and this font with this function of this method is called it will 56 00:06:02,910 --> 00:06:06,480 exit the application from the look. 57 00:06:06,900 --> 00:06:14,190 One more thing I want to do before we wrap up this video lecture I want to create on another function 58 00:06:15,000 --> 00:06:16,770 this time I'll call it 59 00:06:19,220 --> 00:06:26,890 can't on the score wait but feel free to call use whatever you like. 60 00:06:27,140 --> 00:06:38,420 And then the parentheses and the call on and I'm going to create a variable and I'm going to call this 61 00:06:38,420 --> 00:06:53,170 variable time left and and went to set that to a course to the end time variable which is this variable 62 00:06:53,170 --> 00:06:53,560 here. 63 00:06:53,560 --> 00:07:11,560 The global one so I'm certain it two equals two that minus the date time dot the time date time the 64 00:07:11,560 --> 00:07:12,560 day time dot. 65 00:07:12,570 --> 00:07:22,570 Now that this is method a time function we've imported the day time and the time module has we're able 66 00:07:22,570 --> 00:07:25,230 to utilize it here. 67 00:07:25,300 --> 00:07:28,890 This will give us the current time. 68 00:07:29,530 --> 00:07:36,630 So if we take away B value of this and time from this method here it will give us the time left over 69 00:07:36,670 --> 00:07:39,250 for our event. 70 00:07:39,340 --> 00:07:46,380 I have added some more line of code so as to save time so a mother this line here. 71 00:07:46,390 --> 00:07:53,300 What this does it takes away the micro seconds. 72 00:07:53,380 --> 00:07:53,730 Okay. 73 00:07:53,760 --> 00:08:01,270 So if without doubt the time would display after the cyclone Yasi tore through so sure some microseconds. 74 00:08:01,270 --> 00:08:08,920 So I'm using this value here to take away the microsecond so that we don't have that displayed and then 75 00:08:08,920 --> 00:08:10,880 here I have created. 76 00:08:10,900 --> 00:08:15,710 This is what will display the clock. 77 00:08:16,040 --> 00:08:21,640 Ok this will show the time that is left to your particular event. 78 00:08:21,640 --> 00:08:26,740 This is what we've used to set that time. 79 00:08:26,740 --> 00:08:38,150 And this here this piece of code here is used to trigger the countdown after one thousand milli seconds. 80 00:08:38,290 --> 00:08:47,200 So I'm going to end this lecture here and we'll continue in part to where we'll start to build the interface 81 00:08:47,320 --> 00:08:50,230 for the countdown clock. 82 00:08:50,230 --> 00:08:51,580 So make sure you save your work. 83 00:08:51,580 --> 00:08:55,870 Just keep files save and we'll see you in part two. 84 00:08:55,870 --> 00:08:56,800 Thanks for watching. 85 00:08:56,800 --> 00:08:57,450 Bye for now.